ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-10-15 02:24:49
Exec Total Coverage
Lines: 1991 4584 43.4%
Functions: 127 337 37.7%
Branches: 1346 3784 35.6%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/frame_timings.h"
27 #include "zc/replay_upload.h"
28 #include "zc/zasm_pipeline.h"
29 #include "zc/zc_init.h"
30 #include "init.h"
31 #include "zc/replay.h"
32 #include "zc/cheats.h"
33 #include "zc/render.h"
34 #include "base/zc_math.h"
35 #include "base/zapp.h"
36 #include "dialog/cheatkeys.h"
37 #include "metadata/metadata.h"
38 #include "zc/zelda.h"
39 #include "zc/saves.h"
40 #include "tiles.h"
41 #include "base/colors.h"
42 #include "pal.h"
43 #include "base/zsys.h"
44 #include "base/qst.h"
45 #include "zc/zc_sys.h"
46 #include "play_midi.h"
47 #include "gui/jwin_a5.h"
48 #include "base/jwinfsel.h"
49 #include "base/gui.h"
50 #include "midi.h"
51 #include "subscr.h"
52 #include "zc/maps.h"
53 #include "sprite.h"
54 #include "zc/guys.h"
55 #include "zc/hero.h"
56 #include "zc/title.h"
57 #include "particles.h"
58 #include "sound/zcmusic.h"
59 #include "zc/ffscript.h"
60 #include "dialog/info.h"
61 #include "dialog/alert.h"
62 #include "zc/combos.h"
63 #include "zc/jit.h"
64 #include "zc/zc_subscr.h"
65 #include <fmt/format.h>
66 #include "zconsole/ConsoleLogger.h"
67 #include "zinfo.h"
68 #include "base/misctypes.h"
69 #include "music_playback.h"
70 #include "base/new_menu.h"
71 #include "base/files.h"
72 #include "iter.h"
73
74 #ifdef __EMSCRIPTEN__
75 #include "base/emscripten_utils.h"
76 #endif
77
78 using namespace std::chrono_literals;
79
80 extern bool Playing;
81 int32_t sfx_voice[WAV_COUNT];
82 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
83 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
84
85 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
86 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
87
88 extern byte monochrome_console;
89
90 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
91 extern std::string loadlast;
92 extern char *sfx_string[WAV_COUNT];
93 byte use_dwm_flush;
94 byte use_save_indicator;
95 int32_t paused_midi_pos = 0;
96 byte midi_suspended = 0;
97 byte zc_192b163_warp_compatibility;
98 bool epilepsyFlashReduction;
99 signed char pause_in_background_menu_init = 0;
100 byte pause_in_background = 0;
101 bool is_sys_pal = false;
102 static bool load_control_called_this_frame;
103 extern PALETTE* hw_palette;
104 extern bool update_hw_pal;
105 extern const char* dmaplist(int32_t index, int32_t* list_size);
106 int32_t getnumber(const char *prompt,int32_t initialval);
107
108 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
109 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
110
111 #ifdef ALLEGRO_LINUX
112 static const char *samplepath = "samplesoundset/patches.dat";
113 #endif
114 char qst_files_path[2048];
115
116 extern TopMenu the_player_menu;
117 #ifdef _MSC_VER
118 #define getcwd _getcwd
119 #endif
120
121 bool rF11();
122 bool rI();
123 bool rQ();
124 bool zc_key_pressed();
125
126 #ifdef _WIN32
127
128 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
129 extern "C"
130 {
131 typedef HRESULT(WINAPI *t_DwmFlush)();
132 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
133 }
134
135 void do_DwmFlush()
136 {
137 static HMODULE shell = LoadLibrary("dwmapi.dll");
138
139 if(!shell)
140 return;
141
142 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
143 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
144
145 BOOL enabled;
146 isEnabled(&enabled);
147
148 if(isEnabled)
149 flush();
150 }
151
152 #endif // _WIN32
153
154 315 void zc_exit(int code)
155 {
156 extern CConsoleLoggerEx zscript_coloured_console;
157
158 315 set_is_exiting();
159
160
1/2
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
315 if (replay_get_mode() == ReplayMode::Record) replay_save();
161 315 replay_stop();
162 315 music_stop();
163 315 kill_sfx();
164
165
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 306 times.
315 if (get_qr(qr_OLD_SCRIPT_VOLUME))
166 {
167 //restore user volume settings
168
2/2
✓ Branch 0 taken 305 times.
✓ Branch 1 taken 1 times.
306 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
169 {
170 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
171 1 }
172
2/2
✓ Branch 0 taken 305 times.
✓ Branch 1 taken 1 times.
306 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
173 {
174 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
175 1 }
176
2/2
✓ Branch 0 taken 305 times.
✓ Branch 1 taken 1 times.
306 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
177 {
178 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
179 1 }
180
1/2
✓ Branch 0 taken 306 times.
✗ Branch 1 not taken.
306 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
181 {
182 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
183 }
184 306 }
185
1/2
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
315 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
186 {
187 pan_style = (int32_t)FFCore.usr_panstyle;
188 }
189 315 save_game_configs();
190
191 315 zscript_coloured_console.kill();
192 315 zasm_pipeline_shutdown();
193 315 frame_timings_end();
194 315 quit_game();
195
196 315 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
197 315 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
198
199 315 allegro_exit();
200 315 exit(code);
201 }
202
203 93594 bool flash_reduction_enabled(bool check_qr)
204 {
205
4/4
✓ Branch 0 taken 88914 times.
✓ Branch 1 taken 4680 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92304 times.
93594 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
206 }
207
208 // Dialogue largening
209 void large_dialog(DIALOG *d)
210 {
211 large_dialog(d, 1.5);
212 }
213
214 void large_dialog(DIALOG *d, float RESIZE_AMT)
215 {
216 if(!d[0].d1)
217 {
218 d[0].d1 = 1;
219 int32_t oldwidth = d[0].w;
220 int32_t oldheight = d[0].h;
221 int32_t oldx = d[0].x;
222 int32_t oldy = d[0].y;
223 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
224 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
225 d[0].w = int32_t(d[0].w*RESIZE_AMT);
226 d[0].h = int32_t(d[0].h*RESIZE_AMT);
227
228 for(int32_t i=1; d[i].proc !=NULL; i++)
229 {
230 // Place elements horizontally
231 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
232 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
233
234 if(d[i].proc != d_stringloader)
235 {
236 if(d[i].proc==d_bitmap_proc)
237 {
238 d[i].w *= 2;
239 }
240 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
241 }
242
243 // Place elements vertically
244 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
245 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
246
247 // Vertically resize elements
248 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
249 {
250 d[i].h = int32_t((double)d[i].h*1.5);
251 }
252 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
253 {
254 d[i].y += int32_t((double)d[i].h*0.25);
255 d[i].h = int32_t((double)d[i].h*1.25);
256 }
257 else if(d[i].proc==d_bitmap_proc)
258 {
259 d[i].h *= 2;
260 }
261 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
262
263 // Fix frames
264 if(d[i].proc == jwin_frame_proc)
265 {
266 d[i].x++;
267 d[i].y++;
268 d[i].w-=4;
269 d[i].h-=4;
270 }
271 }
272 }
273
274 for(int32_t i=1; d[i].proc!=NULL; i++)
275 {
276 if(d[i].proc==jwin_slider_proc)
277 continue;
278
279 // Bigger font
280 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
281
282 if(!d[i].dp2 && bigfontproc)
283 {
284 d[i].dp2 = get_zc_font(font_lfont_l);
285 }
286 else if(!bigfontproc)
287 {
288 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
289 }
290
291 // Make checkboxes work
292 if(d[i].proc == jwin_check_proc)
293 d[i].proc = jwin_checkfont_proc;
294 else if(d[i].proc == jwin_radio_proc)
295 d[i].proc = jwin_radiofont_proc;
296 }
297
298 jwin_center_dialog(d);
299 }
300
301 static char cfg_sect[] = "zeldadx"; //We need to rename this.
302 static char ctrl_sect[] = "Controls";
303 static char sfx_sect[] = "Volume";
304
305 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
306 {
307 return D_O_K;
308 }
309
310 bool is_reserved_key(int c)
311 {
312 switch(c)
313 {
314 case KEY_ESC:
315 return true;
316 }
317 return false;
318 }
319 bool is_reserved_keycombo(int c, int modflag)
320 {
321 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
322 return true;
323 return false;
324 }
325 bool checkcheat(Cheat cheat)
326 {
327 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
328 return true; //Main key pressed
329 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
330 return true; //Alt key pressed
331 return false;
332 }
333 315 void load_default_cheatkeys()
334 {
335 315 memset(cheatkeys, 0, sizeof(cheatkeys));
336 315 cheatkeys[Cheat::Life][0] = KEY_H;
337 315 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
338 315 cheatkeys[Cheat::Magic][0] = KEY_M;
339 315 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
340 315 cheatkeys[Cheat::Rupies][0] = KEY_R;
341 315 cheatkeys[Cheat::Bombs][0] = KEY_B;
342 315 cheatkeys[Cheat::Arrows][0] = KEY_A;
343 315 cheatkeys[Cheat::Clock][0] = KEY_I;
344 315 cheatkeys[Cheat::Walls][0] = KEY_F11;
345 315 cheatkeys[Cheat::Fast][0] = KEY_Q;
346 315 cheatkeys[Cheat::Light][0] = KEY_L;
347 315 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
348 315 cheatkeys[Cheat::Kill][0] = KEY_K;
349 315 cheatkeys[Cheat::GoTo][0] = KEY_G;
350 315 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
351 315 cheatkeys[Cheat::ShowL0][0] = KEY_0;
352 315 cheatkeys[Cheat::ShowL1][0] = KEY_1;
353 315 cheatkeys[Cheat::ShowL2][0] = KEY_2;
354 315 cheatkeys[Cheat::ShowL3][0] = KEY_3;
355 315 cheatkeys[Cheat::ShowL4][0] = KEY_4;
356 315 cheatkeys[Cheat::ShowL5][0] = KEY_5;
357 315 cheatkeys[Cheat::ShowL6][0] = KEY_6;
358 315 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
359 315 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
360 315 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
361 315 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
362 315 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
363 315 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
364 315 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
365 315 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
366 315 }
367
368 static bool loaded_game_configs;
369
370 315 void load_game_configs()
371 {
372 315 loaded_game_configs = true;
373 315 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
374 315 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
375 315 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
376 315 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
377 315 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
378 315 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
379 315 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
380 315 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
381 315 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
382 315 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
383 315 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
384 315 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
385 315 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
386 315 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
387
388 //cheat modifier keya
389 315 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
390 315 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
391 315 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
392 315 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
393
394 //cheat keys
395 315 load_default_cheatkeys();
396 char buf[256];
397
2/2
✓ Branch 0 taken 315 times.
✓ Branch 1 taken 11340 times.
11655 for(size_t q = 1; q < Cheat::Last; ++q)
398 {
399
1/2
✓ Branch 0 taken 11340 times.
✗ Branch 1 not taken.
11340 if(!bindable_cheat((Cheat)q)) continue;
400 11340 std::string cheatname = cheat_to_string((Cheat)q);
401
1/2
✓ Branch 0 taken 11340 times.
✗ Branch 1 not taken.
11340 util::lowerstr(cheatname);
402 11340 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
403
1/2
✓ Branch 0 taken 11340 times.
✗ Branch 1 not taken.
11340 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
404 11340 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
405
1/2
✓ Branch 0 taken 11340 times.
✗ Branch 1 not taken.
11340 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
406 11340 }
407
408
1/2
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
315 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
409 joystick_index = 0;
410
411 315 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
412 315 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
413 315 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
414 315 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
415 315 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
416 315 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
417 315 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
418 315 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
419 315 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
420 315 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
421
422 315 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
423 315 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
424 315 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
425 315 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
426
427 315 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
428 315 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
429 315 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
430 315 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
431 315 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
432 315 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
433 315 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
434 315 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
435 315 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
436 315 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
437 315 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
438
439 315 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
440 315 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
441 315 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
442 315 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
443
444 315 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
445
446 315 midi_volume = zc_get_config(sfx_sect,"midi",255);
447 315 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
448 315 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
449 315 pan_style = zc_get_config(sfx_sect,"pan",1);
450 315 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
451 315 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
452 315 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
453 315 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
454 315 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
455 315 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
456 315 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
457 315 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
458 315 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
459 #ifdef __EMSCRIPTEN__
460 if (em_is_mobile()) NameEntryMode = 2;
461 #endif
462 315 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
463 315 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
464 315 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
465 315 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
466 315 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
467 315 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
468
469 315 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
470 315 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
471 315 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
472 315 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
473 315 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
474 315 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
475 315 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
476
477 315 loadlast = zc_get_config(cfg_sect,"load_last_path","");
478
479 315 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
480
481 315 info_opacity = zc_get_config("zc","debug_info_opacity",255);
482 #ifdef _WIN32
483 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
484 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
485 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
486
487 // This one's for Aero
488 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
489
490 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
491 #else //UNIX
492 315 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
493 315 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
494 #endif
495 315 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
496 315 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
497
498 315 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
499 315 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
500 315 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
501 315 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
502 315 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
503 315 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
504 315 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
505 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
506 315 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
507 315 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
508 315 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
509 315 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
510 315 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
511 315 }
512
513 void save_control_configs(bool kb)
514 {
515 if(kb)
516 {
517 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
518 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
519 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
520 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
521
522 if (!replay_is_replaying())
523 {
524 zc_set_config(ctrl_sect,"key_a",Akey);
525 zc_set_config(ctrl_sect,"key_b",Bkey);
526 zc_set_config(ctrl_sect,"key_s",Skey);
527 zc_set_config(ctrl_sect,"key_l",Lkey);
528 zc_set_config(ctrl_sect,"key_r",Rkey);
529 zc_set_config(ctrl_sect,"key_p",Pkey);
530 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
531 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
532 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
533 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
534 zc_set_config(ctrl_sect,"key_up", DUkey);
535 zc_set_config(ctrl_sect,"key_down", DDkey);
536 zc_set_config(ctrl_sect,"key_left", DLkey);
537 zc_set_config(ctrl_sect,"key_right",DRkey);
538 }
539 }
540 else
541 {
542 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
543 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
544 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
545 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
546 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
547 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
548 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
549 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
550 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
551 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
552 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
553 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
554 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
555 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
556
557 zc_set_config(ctrl_sect,"btn_a",Abtn);
558 zc_set_config(ctrl_sect,"btn_b",Bbtn);
559 zc_set_config(ctrl_sect,"btn_s",Sbtn);
560 zc_set_config(ctrl_sect,"btn_m",Mbtn);
561 zc_set_config(ctrl_sect,"btn_l",Lbtn);
562 zc_set_config(ctrl_sect,"btn_r",Rbtn);
563 zc_set_config(ctrl_sect,"btn_p",Pbtn);
564 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
565 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
566 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
567 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
568
569 zc_set_config(ctrl_sect,"btn_up",DUbtn);
570 zc_set_config(ctrl_sect,"btn_down",DDbtn);
571 zc_set_config(ctrl_sect,"btn_left",DLbtn);
572 zc_set_config(ctrl_sect,"btn_right",DRbtn);
573 }
574 }
575
576 void save_cheatkeys()
577 {
578 char buf[256];
579 for(size_t q = 1; q < Cheat::Last; ++q)
580 {
581 if(!bindable_cheat((Cheat)q)) continue;
582 std::string cheatname = cheat_to_string((Cheat)q);
583 util::lowerstr(cheatname);
584 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
585 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
586 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
587 if(cheatkeys[q][1])
588 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
589 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
590 }
591 }
592
593 315 void save_game_configs()
594 {
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 315 times.
315 if (!loaded_game_configs) return;
596
597 315 packfile_password("");
598
599
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
315 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
600 {
601 int o_window_x, o_window_y;
602 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
603 zc_set_config(cfg_sect,"window_x",o_window_x);
604 zc_set_config(cfg_sect,"window_y",o_window_y);
605 }
606
607
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 315 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
315 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
608 {
609 window_width = al_get_display_width(all_get_display());
610 window_height = al_get_display_height(all_get_display());
611 zc_set_config(cfg_sect,"window_width",window_width);
612 zc_set_config(cfg_sect,"window_height",window_height);
613 }
614
615 315 zc_set_config(cfg_sect,"load_last_path",loadlast.c_str());
616 315 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
617
618 315 flush_config_file();
619 #ifdef __EMSCRIPTEN__
620 em_sync_fs();
621 #endif
622 315 }
623
624 //----------------------------------------------------------------
625
626 // Timers
627
628 38001 void fps_callback()
629 {
630 38001 lastfps=framecnt;
631 38001 framecnt=0;
632 38001 }
633
634 END_OF_FUNCTION(fps_callback)
635
636 315 int32_t Z_init_timers()
637 {
638 static bool didit = false;
639 const static char *err_str = "Couldn't allocate timer";
640 315 err_str = err_str; //Unused variable warning
641
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 315 times.
315 if(didit)
643 return 1;
644
645 315 didit = true;
646
647 LOCK_VARIABLE(lastfps);
648 LOCK_VARIABLE(framecnt);
649 LOCK_FUNCTION(fps_callback);
650
651
1/2
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
315 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
652 return 0;
653
654 315 return 1;
655 315 }
656
657 315 void Z_remove_timers()
658 {
659 315 remove_int(fps_callback);
660 315 }
661
662 //----------------------------------------------------------------
663
664 void go()
665 {
666 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
667 }
668
669 void comeback()
670 {
671 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
672 }
673
674 void dump_pal(BITMAP *dest)
675 {
676 for(int32_t i=0; i<256; i++)
677 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
678 }
679
680 //----------------------------------------------------------------
681
682 int game_mouse_index = ZCM_BLANK;
683 static bool system_mouse = false;
684 94 bool sys_mouse()
685 {
686 94 system_mouse = true;
687 94 return MouseSprite::set(ZCM_NORMAL);
688 }
689 1632 bool game_mouse()
690 {
691 1632 system_mouse = false;
692 1632 return MouseSprite::set(game_mouse_index);
693 }
694 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
695 {
696 if(!bmp)
697 return;
698 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
699 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
700 if(bmp->w == scaledw && bmp->h == scaledh)
701 user_scale = false;
702 if(user_scale || sys_recolor)
703 {
704 if(!user_scale) scale = 1;
705 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
706 if(user_scale)
707 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
708 else
709 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
710 if(sys_recolor)
711 recolor_mouse(tmpbmp);
712 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
713 destroy_bitmap(tmpbmp);
714 }
715 else
716 {
717 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
718 }
719 }
720
721 //Handles converting the mouse sprite from the .dat file
722 void recolor_mouse(BITMAP* bmp)
723 {
724 for(int32_t x = 0; x < bmp->w; ++x)
725 {
726 for(int32_t y = 0; y < bmp->h; ++y)
727 {
728 int32_t color = getpixel(bmp, x, y);
729 switch(color)
730 {
731 case dvc(1):
732 color = jwin_pal[jcCURSORMISC];
733 break;
734 case dvc(2):
735 color = jwin_pal[jcCURSOROUTLINE];
736 break;
737 case dvc(3):
738 color = jwin_pal[jcCURSORLIGHT];
739 break;
740 case dvc(5):
741 color = jwin_pal[jcCURSORDARK];
742 break;
743 default:
744 continue;
745 }
746 putpixel(bmp, x, y, color);
747 }
748 }
749 }
750 void load_mouse()
751 {
752 PALETTE pal;
753 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
754 if (!cursor_bitmap)
755 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
756
757 enter_sys_pal();
758 MouseSprite::set(-1);
759 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
760 int32_t sz = 16*scale;
761 for(int32_t j = 0; j < 1; ++j)
762 {
763 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
764 if(zcmouse[j])
765 destroy_bitmap(zcmouse[j]);
766 zcmouse[j] = create_bitmap_ex(8,sz,sz);
767 clear_bitmap(zcmouse[j]);
768 clear_bitmap(tmpbmp);
769 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
770 recolor_mouse(tmpbmp);
771 if(sz!=16)
772 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
773 else
774 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
775 destroy_bitmap(tmpbmp);
776 }
777 if(!hw_palette) hw_palette = &RAMpal;
778 zc_set_palette(*hw_palette);
779
780 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
781 clear_bitmap(blankmouse);
782
783 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
784 MouseSprite::assign(ZCM_BLANK, blankmouse);
785 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
786
787 //Reload the mouse
788 if(system_mouse)
789 sys_mouse();
790 else game_mouse();
791
792 destroy_bitmap(blankmouse);
793 destroy_bitmap(cursor_bitmap);
794 exit_sys_pal();
795 }
796
797 // sets the video mode and initializes the palette and mouse sprite
798 315 bool game_vid_mode(int32_t mode,int32_t wait)
799 {
800
1/2
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
315 if (is_headless())
801 315 return true;
802
803 extern int zq_screen_w, zq_screen_h;
804 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
805 {
806 return false;
807 }
808
809 scrx = (resx-320)>>1;
810 scry = (resy-240)>>1;
811 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
812 zcmouse[q] = NULL;
813 load_mouse();
814
815 for(int32_t i=240; i<256; i++)
816 RAMpal[i]=pal_gui[i];
817
818 zc_set_palette(RAMpal);
819 clear_to_color(screen,BLACK);
820
821 rest(wait);
822 return true;
823 315 }
824
825 323 void null_quest()
826 {
827
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 std::string title_assets_path = "modules/classic/title_gfx.dat";
828
2/4
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 323 times.
323 if (get_last_loaded_qstpath() == title_assets_path)
829 return;
830
831 byte skip_flags[4];
832
2/2
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 8398 times.
8721 for (int i = 0; i < skip_max; i++)
833
1/2
✓ Branch 0 taken 8398 times.
✗ Branch 1 not taken.
8398 set_bit(skip_flags, i, 1);
834
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 set_bit(skip_flags, skip_tiles, 0);
835
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 set_bit(skip_flags, skip_csets, 0);
836
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
837
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
838 323 sfxdat = 1;
839 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
840 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
841 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
842 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 323 times.
323 }
844
845 323 void init_NES_mode()
846 {
847 323 null_quest();
848 323 }
849
850 //----------------------------------------------------------------
851
852 qword trianglelines[16]=
853 {
854 0x0000000000000000ULL,
855 0xFD00000000000000ULL,
856 0xFDFD000000000000ULL,
857 0xFDFDFD0000000000ULL,
858 0xFDFDFDFD00000000ULL,
859 0xFDFDFDFDFD000000ULL,
860 0xFDFDFDFDFDFD0000ULL,
861 0xFDFDFDFDFDFDFD00ULL,
862 0xFDFDFDFDFDFDFDFDULL,
863 0x00FDFDFDFDFDFDFDULL,
864 0x0000FDFDFDFDFDFDULL,
865 0x000000FDFDFDFDFDULL,
866 0x00000000FDFDFDFDULL,
867 0x0000000000FDFDFDULL,
868 0x000000000000FDFDULL,
869 0x00000000000000FDULL,
870 };
871
872 word screen_triangles[29][32];
873
874 // the ULL suffixes are to prevent this warning:
875 // warning: integer constant is too large for "int32_t" type
876
877 qword triangles[4][16][8]= //[direction][value][line]
878 {
879 {
880 {
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL,
887 0x0000000000000000ULL,
888 0x0000000000000000ULL
889 },
890 {
891 0xFD00000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL,
897 0x0000000000000000ULL,
898 0x0000000000000000ULL
899 },
900 {
901 0xFDFD000000000000ULL,
902 0xFD00000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL,
907 0x0000000000000000ULL,
908 0x0000000000000000ULL
909 },
910 {
911 0xFDFDFD0000000000ULL,
912 0xFDFD000000000000ULL,
913 0xFD00000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL,
916 0x0000000000000000ULL,
917 0x0000000000000000ULL,
918 0x0000000000000000ULL
919 },
920 {
921 0xFDFDFDFD00000000ULL,
922 0xFDFDFD0000000000ULL,
923 0xFDFD000000000000ULL,
924 0xFD00000000000000ULL,
925 0x0000000000000000ULL,
926 0x0000000000000000ULL,
927 0x0000000000000000ULL,
928 0x0000000000000000ULL
929 },
930 {
931 0xFDFDFDFDFD000000ULL,
932 0xFDFDFDFD00000000ULL,
933 0xFDFDFD0000000000ULL,
934 0xFDFD000000000000ULL,
935 0xFD00000000000000ULL,
936 0x0000000000000000ULL,
937 0x0000000000000000ULL,
938 0x0000000000000000ULL
939 },
940 {
941 0xFDFDFDFDFDFD0000ULL,
942 0xFDFDFDFDFD000000ULL,
943 0xFDFDFDFD00000000ULL,
944 0xFDFDFD0000000000ULL,
945 0xFDFD000000000000ULL,
946 0xFD00000000000000ULL,
947 0x0000000000000000ULL,
948 0x0000000000000000ULL
949 },
950 {
951 0xFDFDFDFDFDFDFD00ULL,
952 0xFDFDFDFDFDFD0000ULL,
953 0xFDFDFDFDFD000000ULL,
954 0xFDFDFDFD00000000ULL,
955 0xFDFDFD0000000000ULL,
956 0xFDFD000000000000ULL,
957 0xFD00000000000000ULL,
958 0x0000000000000000ULL
959 },
960 {
961 0xFDFDFDFDFDFDFDFDULL,
962 0xFDFDFDFDFDFDFD00ULL,
963 0xFDFDFDFDFDFD0000ULL,
964 0xFDFDFDFDFD000000ULL,
965 0xFDFDFDFD00000000ULL,
966 0xFDFDFD0000000000ULL,
967 0xFDFD000000000000ULL,
968 0xFD00000000000000ULL
969 },
970 {
971 0xFDFDFDFDFDFDFDFDULL,
972 0xFDFDFDFDFDFDFDFDULL,
973 0xFDFDFDFDFDFDFD00ULL,
974 0xFDFDFDFDFDFD0000ULL,
975 0xFDFDFDFDFD000000ULL,
976 0xFDFDFDFD00000000ULL,
977 0xFDFDFD0000000000ULL,
978 0xFDFD000000000000ULL
979 },
980 {
981 0xFDFDFDFDFDFDFDFDULL,
982 0xFDFDFDFDFDFDFDFDULL,
983 0xFDFDFDFDFDFDFDFDULL,
984 0xFDFDFDFDFDFDFD00ULL,
985 0xFDFDFDFDFDFD0000ULL,
986 0xFDFDFDFDFD000000ULL,
987 0xFDFDFDFD00000000ULL,
988 0xFDFDFD0000000000ULL
989 },
990 {
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFDFDULL,
993 0xFDFDFDFDFDFDFDFDULL,
994 0xFDFDFDFDFDFDFDFDULL,
995 0xFDFDFDFDFDFDFD00ULL,
996 0xFDFDFDFDFDFD0000ULL,
997 0xFDFDFDFDFD000000ULL,
998 0xFDFDFDFD00000000ULL
999 },
1000 {
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFDFDULL,
1005 0xFDFDFDFDFDFDFDFDULL,
1006 0xFDFDFDFDFDFDFD00ULL,
1007 0xFDFDFDFDFDFD0000ULL,
1008 0xFDFDFDFDFD000000ULL
1009 },
1010 {
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFDFDULL,
1016 0xFDFDFDFDFDFDFDFDULL,
1017 0xFDFDFDFDFDFDFD00ULL,
1018 0xFDFDFDFDFDFD0000ULL
1019 },
1020 {
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFDFDULL,
1027 0xFDFDFDFDFDFDFDFDULL,
1028 0xFDFDFDFDFDFDFD00ULL
1029 },
1030 {
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL,
1036 0xFDFDFDFDFDFDFDFDULL,
1037 0xFDFDFDFDFDFDFDFDULL,
1038 0xFDFDFDFDFDFDFDFDULL
1039 }
1040 },
1041 {
1042 {
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL,
1049 0x0000000000000000ULL,
1050 0x0000000000000000ULL
1051 },
1052 {
1053 0x00000000000000FDULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL,
1059 0x0000000000000000ULL,
1060 0x0000000000000000ULL
1061 },
1062 {
1063 0x000000000000FDFDULL,
1064 0x00000000000000FDULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL
1071 },
1072 {
1073 0x0000000000FDFDFDULL,
1074 0x000000000000FDFDULL,
1075 0x00000000000000FDULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL
1081 },
1082 {
1083 0x00000000FDFDFDFDULL,
1084 0x0000000000FDFDFDULL,
1085 0x000000000000FDFDULL,
1086 0x00000000000000FDULL,
1087 0x0000000000000000ULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL,
1090 0x0000000000000000ULL
1091 },
1092 {
1093 0x000000FDFDFDFDFDULL,
1094 0x00000000FDFDFDFDULL,
1095 0x0000000000FDFDFDULL,
1096 0x000000000000FDFDULL,
1097 0x00000000000000FDULL,
1098 0x0000000000000000ULL,
1099 0x0000000000000000ULL,
1100 0x0000000000000000ULL
1101 },
1102 {
1103 0x0000FDFDFDFDFDFDULL,
1104 0x000000FDFDFDFDFDULL,
1105 0x00000000FDFDFDFDULL,
1106 0x0000000000FDFDFDULL,
1107 0x000000000000FDFDULL,
1108 0x00000000000000FDULL,
1109 0x0000000000000000ULL,
1110 0x0000000000000000ULL
1111 },
1112 {
1113 0x00FDFDFDFDFDFDFDULL,
1114 0x0000FDFDFDFDFDFDULL,
1115 0x000000FDFDFDFDFDULL,
1116 0x00000000FDFDFDFDULL,
1117 0x0000000000FDFDFDULL,
1118 0x000000000000FDFDULL,
1119 0x00000000000000FDULL,
1120 0x0000000000000000ULL
1121 },
1122 {
1123 0xFDFDFDFDFDFDFDFDULL,
1124 0x00FDFDFDFDFDFDFDULL,
1125 0x0000FDFDFDFDFDFDULL,
1126 0x000000FDFDFDFDFDULL,
1127 0x00000000FDFDFDFDULL,
1128 0x0000000000FDFDFDULL,
1129 0x000000000000FDFDULL,
1130 0x00000000000000FDULL
1131 },
1132 {
1133 0xFDFDFDFDFDFDFDFDULL,
1134 0xFDFDFDFDFDFDFDFDULL,
1135 0x00FDFDFDFDFDFDFDULL,
1136 0x0000FDFDFDFDFDFDULL,
1137 0x000000FDFDFDFDFDULL,
1138 0x00000000FDFDFDFDULL,
1139 0x0000000000FDFDFDULL,
1140 0x000000000000FDFDULL
1141 },
1142 {
1143 0xFDFDFDFDFDFDFDFDULL,
1144 0xFDFDFDFDFDFDFDFDULL,
1145 0xFDFDFDFDFDFDFDFDULL,
1146 0x00FDFDFDFDFDFDFDULL,
1147 0x0000FDFDFDFDFDFDULL,
1148 0x000000FDFDFDFDFDULL,
1149 0x00000000FDFDFDFDULL,
1150 0x0000000000FDFDFDULL
1151 },
1152 {
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0xFDFDFDFDFDFDFDFDULL,
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0xFDFDFDFDFDFDFDFDULL,
1157 0x00FDFDFDFDFDFDFDULL,
1158 0x0000FDFDFDFDFDFDULL,
1159 0x000000FDFDFDFDFDULL,
1160 0x00000000FDFDFDFDULL
1161 },
1162 {
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0xFDFDFDFDFDFDFDFDULL,
1168 0x00FDFDFDFDFDFDFDULL,
1169 0x0000FDFDFDFDFDFDULL,
1170 0x000000FDFDFDFDFDULL
1171 },
1172 {
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0x00FDFDFDFDFDFDFDULL,
1180 0x0000FDFDFDFDFDFDULL
1181 },
1182 {
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0x00FDFDFDFDFDFDFDULL
1191 },
1192 {
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL,
1200 0xFDFDFDFDFDFDFDFDULL
1201 }
1202 },
1203 {
1204 {
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL,
1211 0x0000000000000000ULL,
1212 0x0000000000000000ULL
1213 },
1214 {
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0x0000000000000000ULL,
1221 0x0000000000000000ULL,
1222 0xFD00000000000000ULL
1223 },
1224 {
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0x0000000000000000ULL,
1231 0xFD00000000000000ULL,
1232 0xFDFD000000000000ULL
1233 },
1234 {
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL,
1238 0x0000000000000000ULL,
1239 0x0000000000000000ULL,
1240 0xFD00000000000000ULL,
1241 0xFDFD000000000000ULL,
1242 0xFDFDFD0000000000ULL
1243 },
1244 {
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0x0000000000000000ULL,
1248 0x0000000000000000ULL,
1249 0xFD00000000000000ULL,
1250 0xFDFD000000000000ULL,
1251 0xFDFDFD0000000000ULL,
1252 0xFDFDFDFD00000000ULL
1253 },
1254 {
1255 0x0000000000000000ULL,
1256 0x0000000000000000ULL,
1257 0x0000000000000000ULL,
1258 0xFD00000000000000ULL,
1259 0xFDFD000000000000ULL,
1260 0xFDFDFD0000000000ULL,
1261 0xFDFDFDFD00000000ULL,
1262 0xFDFDFDFDFD000000ULL
1263 },
1264 {
1265 0x0000000000000000ULL,
1266 0x0000000000000000ULL,
1267 0xFD00000000000000ULL,
1268 0xFDFD000000000000ULL,
1269 0xFDFDFD0000000000ULL,
1270 0xFDFDFDFD00000000ULL,
1271 0xFDFDFDFDFD000000ULL,
1272 0xFDFDFDFDFDFD0000ULL
1273 },
1274 {
1275 0x0000000000000000ULL,
1276 0xFD00000000000000ULL,
1277 0xFDFD000000000000ULL,
1278 0xFDFDFD0000000000ULL,
1279 0xFDFDFDFD00000000ULL,
1280 0xFDFDFDFDFD000000ULL,
1281 0xFDFDFDFDFDFD0000ULL,
1282 0xFDFDFDFDFDFDFD00ULL
1283 },
1284 {
1285 0xFD00000000000000ULL,
1286 0xFDFD000000000000ULL,
1287 0xFDFDFD0000000000ULL,
1288 0xFDFDFDFD00000000ULL,
1289 0xFDFDFDFDFD000000ULL,
1290 0xFDFDFDFDFDFD0000ULL,
1291 0xFDFDFDFDFDFDFD00ULL,
1292 0xFDFDFDFDFDFDFDFDULL
1293 },
1294 {
1295 0xFDFD000000000000ULL,
1296 0xFDFDFD0000000000ULL,
1297 0xFDFDFDFD00000000ULL,
1298 0xFDFDFDFDFD000000ULL,
1299 0xFDFDFDFDFDFD0000ULL,
1300 0xFDFDFDFDFDFDFD00ULL,
1301 0xFDFDFDFDFDFDFDFDULL,
1302 0xFDFDFDFDFDFDFDFDULL
1303 },
1304 {
1305 0xFDFDFD0000000000ULL,
1306 0xFDFDFDFD00000000ULL,
1307 0xFDFDFDFDFD000000ULL,
1308 0xFDFDFDFDFDFD0000ULL,
1309 0xFDFDFDFDFDFDFD00ULL,
1310 0xFDFDFDFDFDFDFDFDULL,
1311 0xFDFDFDFDFDFDFDFDULL,
1312 0xFDFDFDFDFDFDFDFDULL
1313 },
1314 {
1315 0xFDFDFDFD00000000ULL,
1316 0xFDFDFDFDFD000000ULL,
1317 0xFDFDFDFDFDFD0000ULL,
1318 0xFDFDFDFDFDFDFD00ULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0xFDFDFDFDFDFDFDFDULL,
1321 0xFDFDFDFDFDFDFDFDULL,
1322 0xFDFDFDFDFDFDFDFDULL
1323 },
1324 {
1325 0xFDFDFDFDFD000000ULL,
1326 0xFDFDFDFDFDFD0000ULL,
1327 0xFDFDFDFDFDFDFD00ULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL,
1332 0xFDFDFDFDFDFDFDFDULL
1333 },
1334 {
1335 0xFDFDFDFDFDFD0000ULL,
1336 0xFDFDFDFDFDFDFD00ULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL,
1342 0xFDFDFDFDFDFDFDFDULL
1343 },
1344 {
1345 0xFDFDFDFDFDFDFD00ULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0xFDFDFDFDFDFDFDFDULL
1353 },
1354 {
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL,
1362 0xFDFDFDFDFDFDFDFDULL
1363 }
1364 },
1365 {
1366 {
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL,
1373 0x0000000000000000ULL,
1374 0x0000000000000000ULL
1375 },
1376 {
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x0000000000000000ULL,
1383 0x0000000000000000ULL,
1384 0x00000000000000FDULL
1385 },
1386 {
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x0000000000000000ULL,
1393 0x00000000000000FDULL,
1394 0x000000000000FDFDULL
1395 },
1396 {
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x0000000000000000ULL,
1402 0x00000000000000FDULL,
1403 0x000000000000FDFDULL,
1404 0x0000000000FDFDFDULL
1405 },
1406 {
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0x0000000000000000ULL,
1410 0x0000000000000000ULL,
1411 0x00000000000000FDULL,
1412 0x000000000000FDFDULL,
1413 0x0000000000FDFDFDULL,
1414 0x00000000FDFDFDFDULL
1415 },
1416 {
1417 0x0000000000000000ULL,
1418 0x0000000000000000ULL,
1419 0x0000000000000000ULL,
1420 0x00000000000000FDULL,
1421 0x000000000000FDFDULL,
1422 0x0000000000FDFDFDULL,
1423 0x00000000FDFDFDFDULL,
1424 0x000000FDFDFDFDFDULL
1425 },
1426 {
1427 0x0000000000000000ULL,
1428 0x0000000000000000ULL,
1429 0x00000000000000FDULL,
1430 0x000000000000FDFDULL,
1431 0x0000000000FDFDFDULL,
1432 0x00000000FDFDFDFDULL,
1433 0x000000FDFDFDFDFDULL,
1434 0x0000FDFDFDFDFDFDULL
1435 },
1436 {
1437 0x0000000000000000ULL,
1438 0x00000000000000FDULL,
1439 0x000000000000FDFDULL,
1440 0x0000000000FDFDFDULL,
1441 0x00000000FDFDFDFDULL,
1442 0x000000FDFDFDFDFDULL,
1443 0x0000FDFDFDFDFDFDULL,
1444 0x00FDFDFDFDFDFDFDULL
1445 },
1446 {
1447 0x00000000000000FDULL,
1448 0x000000000000FDFDULL,
1449 0x0000000000FDFDFDULL,
1450 0x00000000FDFDFDFDULL,
1451 0x000000FDFDFDFDFDULL,
1452 0x0000FDFDFDFDFDFDULL,
1453 0x00FDFDFDFDFDFDFDULL,
1454 0xFDFDFDFDFDFDFDFDULL
1455 },
1456 {
1457 0x000000000000FDFDULL,
1458 0x0000000000FDFDFDULL,
1459 0x00000000FDFDFDFDULL,
1460 0x000000FDFDFDFDFDULL,
1461 0x0000FDFDFDFDFDFDULL,
1462 0x00FDFDFDFDFDFDFDULL,
1463 0xFDFDFDFDFDFDFDFDULL,
1464 0xFDFDFDFDFDFDFDFDULL
1465 },
1466 {
1467 0x0000000000FDFDFDULL,
1468 0x00000000FDFDFDFDULL,
1469 0x000000FDFDFDFDFDULL,
1470 0x0000FDFDFDFDFDFDULL,
1471 0x00FDFDFDFDFDFDFDULL,
1472 0xFDFDFDFDFDFDFDFDULL,
1473 0xFDFDFDFDFDFDFDFDULL,
1474 0xFDFDFDFDFDFDFDFDULL
1475 },
1476 {
1477 0x00000000FDFDFDFDULL,
1478 0x000000FDFDFDFDFDULL,
1479 0x0000FDFDFDFDFDFDULL,
1480 0x00FDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL,
1482 0xFDFDFDFDFDFDFDFDULL,
1483 0xFDFDFDFDFDFDFDFDULL,
1484 0xFDFDFDFDFDFDFDFDULL
1485 },
1486 {
1487 0x000000FDFDFDFDFDULL,
1488 0x0000FDFDFDFDFDFDULL,
1489 0x00FDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL,
1493 0xFDFDFDFDFDFDFDFDULL,
1494 0xFDFDFDFDFDFDFDFDULL
1495 },
1496 {
1497 0x0000FDFDFDFDFDFDULL,
1498 0x00FDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL,
1503 0xFDFDFDFDFDFDFDFDULL,
1504 0xFDFDFDFDFDFDFDFDULL
1505 },
1506 {
1507 0x00FDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL
1515 },
1516 {
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL,
1524 0xFDFDFDFDFDFDFDFDULL
1525 }
1526 }
1527 };
1528
1529 static bool is_opening_screen;
1530 int32_t black_opening_count=0;
1531 int32_t black_opening_x,black_opening_y;
1532 int32_t black_opening_shape;
1533
1534 3284 int32_t choose_opening_shape()
1535 {
1536 // First, count how many bits are set
1537 3284 int32_t numBits=0;
1538 int32_t bitCounter;
1539
1540
2/2
✓ Branch 0 taken 16420 times.
✓ Branch 1 taken 3284 times.
19704 for(int32_t i=0; i<bosMAX; i++)
1541 {
1542
2/2
✓ Branch 0 taken 12920 times.
✓ Branch 1 taken 3500 times.
16420 if(COOLSCROLL&(1<<i))
1543 3500 numBits++;
1544 16420 }
1545
1546 // Shouldn't happen...
1547
1/2
✓ Branch 0 taken 3284 times.
✗ Branch 1 not taken.
3284 if(numBits==0)
1548 return bosCIRCLE;
1549
1550 // Pick a bit
1551 3284 bitCounter=zc_rand()%numBits+1;
1552
1553
2/2
✓ Branch 0 taken 4481 times.
✓ Branch 1 taken 26 times.
4507 for(int32_t i=0; i<bosMAX; i++)
1554 {
1555 // If this bit is set, decrement the bit counter
1556
2/2
✓ Branch 0 taken 1067 times.
✓ Branch 1 taken 3414 times.
4481 if(COOLSCROLL&(1<<i))
1557 3414 bitCounter--;
1558
1559 // When the counter hits 0, return a value based on
1560 // which bit it stopped on.
1561 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1562
2/2
✓ Branch 0 taken 3258 times.
✓ Branch 1 taken 1223 times.
4481 if(bitCounter==0)
1563 3258 return i;
1564 1223 }
1565
1566 // Shouldn't be necessary, but the compiler might complain, at least
1567 26 return bosCIRCLE;
1568 3284 }
1569
1570 739 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1571 {
1572 739 x -= viewport.x;
1573 739 y -= viewport.y;
1574
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 729 times.
739 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1575
1576 739 int32_t w=framebuf->w, h=framebuf->h;
1577 739 int32_t blockrows=h/8, blockcolumns=32;
1578 739 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1579
1580
2/2
✓ Branch 0 taken 20692 times.
✓ Branch 1 taken 739 times.
21431 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1581 {
1582
2/2
✓ Branch 0 taken 662144 times.
✓ Branch 1 taken 20692 times.
682836 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1583 {
1584
2/2
✓ Branch 0 taken 273677 times.
✓ Branch 1 taken 388467 times.
662144 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1585 662144 }
1586 20692 }
1587
1588 739 black_opening_count = 66;
1589 739 black_opening_x = x;
1590 739 black_opening_y = y;
1591 739 lensclk = 0;
1592 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1593
1594
1595
1/2
✓ Branch 0 taken 739 times.
✗ Branch 1 not taken.
739 if(black_opening_shape == bosFADEBLACK)
1596 {
1597 refreshTints();
1598 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1599 }
1600
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 14 times.
739 if(wait)
1601 {
1602 14 FFCore.warpScriptCheck();
1603
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 924 times.
938 for(int32_t i=0; i<66; i++)
1604 {
1605 924 draw_screen();
1606 924 advanceframe(true);
1607
1608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924 times.
924 if(Quit)
1609 {
1610 break;
1611 }
1612 924 }
1613 14 }
1614 739 }
1615
1616 2565 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1617 {
1618 2565 x -= viewport.x;
1619 2565 y -= viewport.y;
1620
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2555 times.
2565 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1621
1622 2565 int32_t w=framebuf->w, h=framebuf->h;
1623 2565 int32_t blockrows=h/8, blockcolumns=32;
1624 2565 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1625
1626
2/2
✓ Branch 0 taken 71933 times.
✓ Branch 1 taken 2565 times.
74498 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1627 {
1628
2/2
✓ Branch 0 taken 2301856 times.
✓ Branch 1 taken 71933 times.
2373789 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1629 {
1630
2/2
✓ Branch 0 taken 1134649 times.
✓ Branch 1 taken 1167207 times.
2301856 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1631 2301856 }
1632 71933 }
1633
1634 2565 black_opening_count = -66;
1635 2565 black_opening_x = x;
1636 2565 black_opening_y = y;
1637 2565 lensclk = 0;
1638
1/2
✓ Branch 0 taken 2565 times.
✗ Branch 1 not taken.
2565 if(black_opening_shape == bosFADEBLACK)
1639 {
1640 refreshTints();
1641 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1642 }
1643
2/2
✓ Branch 0 taken 361 times.
✓ Branch 1 taken 2204 times.
2565 if(wait)
1644 {
1645 2204 FFCore.warpScriptCheck();
1646
2/2
✓ Branch 0 taken 2203 times.
✓ Branch 1 taken 145475 times.
147678 for(int32_t i=0; i<66; i++)
1647 {
1648 145475 draw_screen();
1649 145475 advanceframe(true);
1650
1651
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 145474 times.
145475 if(Quit)
1652 {
1653 1 break;
1654 }
1655 145474 }
1656 2204 }
1657 2565 }
1658
1659 217751 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1660 {
1661 217751 clear_to_color(tmp_scr,BLACK);
1662 217751 int32_t w=dest->w, h=dest->h;
1663
1664
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 20394 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 185741 times.
217751 switch(black_opening_shape)
1665 {
1666 case bosOVAL:
1667 {
1668 9636 double new_w=(w/2)+abs(w/2-x);
1669 9636 double new_h=(h/2)+abs(h/2-y);
1670 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1671 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1672 9636 break;
1673 }
1674
1675 case bosTRIANGLE:
1676 {
1677 1980 double new_w=(w/2)+abs(w/2-x);
1678 1980 double new_h=(h/2)+abs(h/2-y);
1679 1980 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1680 1980 double P2= (PI/2);
1681 1980 double P23=(2*PI/3);
1682 1980 double P43=(4*PI/3);
1683 1980 double Pa= (-4*PI*a/(3*max_a));
1684 1980 double angle=P2+Pa;
1685 1980 double a0=angle;
1686 1980 double a2=angle+P23;
1687 1980 double a4=angle+P43;
1688 3960 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1689 1980 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1690 1980 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1691 0);
1692 1980 break;
1693 }
1694
1695 case bosSMAS:
1696 {
1697
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 13134 times.
20394 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1698
1699
2/2
✓ Branch 0 taken 571032 times.
✓ Branch 1 taken 20394 times.
591426 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1700 {
1701
2/2
✓ Branch 0 taken 4568256 times.
✓ Branch 1 taken 571032 times.
5139288 for(int32_t linerow=0; linerow<8; ++linerow)
1702 {
1703 4568256 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1704
1705
2/2
✓ Branch 0 taken 146184192 times.
✓ Branch 1 taken 4568256 times.
150752448 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1706 {
1707 438552576 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1708
6/6
✓ Branch 0 taken 105613064 times.
✓ Branch 1 taken 40571128 times.
✓ Branch 2 taken 96455664 times.
✓ Branch 3 taken 49728528 times.
✓ Branch 4 taken 55884536 times.
✓ Branch 5 taken 40571128 times.
146184192 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1709 146184192 [linerow];
1710 146184192 ++triangleline;
1711 146184192 }
1712 4568256 }
1713 571032 }
1714
1715 20394 break;
1716 }
1717
1718 case bosFADEBLACK:
1719 {
1720 if(black_opening_count<0)
1721 {
1722 black_fade(zc_min(-black_opening_count,63));
1723 }
1724 else if(black_opening_count>0)
1725 {
1726 black_fade(63-zc_max(black_opening_count-3,0));
1727 }
1728 else black_fade(0);
1729 return; //no blitting from tmp_scr!
1730 }
1731
1732 185741 case bosCIRCLE:
1733 default:
1734 {
1735 185741 double new_w=(w/2)+abs(w/2-x);
1736 185741 double new_h=(h/2)+abs(h/2-y);
1737 185741 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1738 //circlefill(tmp_scr,x,y,a<<3,0);
1739 185741 circlefill(tmp_scr,x,y,r,0);
1740 185741 break;
1741 }
1742 }
1743
1744 217751 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1745 217751 }
1746
1747 // fadeamnt is 0-63
1748 void black_fade(int32_t fadeamnt)
1749 {
1750 fadeamnt = _rgb_scale_6[fadeamnt];
1751 for(int32_t i=0; i < 0xEF; i++)
1752 {
1753 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1754 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1755 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1756 }
1757
1758 refreshpal = true;
1759 }
1760
1761 //----------------------------------------------------------------
1762
1763 201324810 bool item_disabled(int32_t item) //is this item disabled?
1764 {
1765
2/2
✓ Branch 0 taken 14531964 times.
✓ Branch 1 taken 186792846 times.
201324810 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1766 }
1767
1768 15653682 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1769 {
1770
2/2
✓ Branch 0 taken 257097 times.
✓ Branch 1 taken 15396585 times.
15653682 if(current_item(item_type, true) >=item)
1771 {
1772 257097 return true;
1773 }
1774
1775 15396585 return false;
1776 15653682 }
1777
1778 43612664 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1779 {
1780
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421308 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 28758369 times.
✓ Branch 7 taken 9900449 times.
✓ Branch 8 taken 195066 times.
43612664 switch(item_type)
1781 {
1782 case itype_bomb:
1783 case itype_sbomb:
1784 {
1785 int32_t itemid = getItemID(itemsbuf, item_type, it);
1786
1787 if(itemid == -1)
1788 return false;
1789
1790 return (game->get_item(itemid));
1791 }
1792
1793 case itype_clock:
1794 {
1795 4421308 int32_t itemid = getItemID(itemsbuf, item_type, it);
1796
1797
2/4
✓ Branch 0 taken 4421308 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421308 times.
✗ Branch 3 not taken.
4421308 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1798 return (game->get_item(itemid));
1799 4421308 return Hero.getClock()?1:0;
1800 }
1801
1802 case itype_key:
1803 return (game->get_keys()>0);
1804
1805 case itype_magiccontainer:
1806 return (game->get_maxmagic()>=game->get_mp_per_block());
1807
1808 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1809 {
1810
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1811 {
1812 case -2:
1813 {
1814 for(int32_t i=0; i<MAXLEVELS; i++)
1815 {
1816 if(game->lvlitems[i]&(1 << li_mcguffin))
1817 {
1818 return true;
1819 }
1820 }
1821
1822 return false;
1823 }
1824
1825 case -1:
1826 return (game->lvlitems[dlevel]&(1 << li_mcguffin));
1827
1828 default:
1829
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1830 {
1831 337472 return (game->lvlitems[it]&(1 << li_mcguffin));
1832 }
1833
1834 break;
1835 }
1836
1837 return 0;
1838 }
1839
1840 case itype_map: //it: -2=any, -1=current level, other=that level
1841 {
1842
2/3
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28216743 times.
28758369 switch(it)
1843 {
1844 case -2:
1845 {
1846 for(int32_t i=0; i<MAXLEVELS; i++)
1847 {
1848 if(game->lvlitems[i]&(1 << li_map))
1849 {
1850 return true;
1851 }
1852 }
1853
1854 return false;
1855 }
1856
1857 case -1:
1858 28216743 return (game->lvlitems[dlevel]&(1 << li_map))!=0;
1859
1860 default:
1861
2/4
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 541626 times.
541626 if(it>=0&&it<MAXLEVELS)
1862 {
1863 541626 return (game->lvlitems[it]&(1 << li_map))!=0;
1864 }
1865
1866 break;
1867 }
1868
1869 return 0;
1870 }
1871
1872 case itype_compass: //it: -2=any, -1=current level, other=that level
1873 {
1874
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9900449 times.
9900449 switch(it)
1875 {
1876 case -2:
1877 {
1878 for(int32_t i=0; i<MAXLEVELS; i++)
1879 {
1880 if(game->lvlitems[i]&(1 << li_compass))
1881 {
1882 return true;
1883 }
1884 }
1885
1886 return false;
1887 }
1888
1889 case -1:
1890 9900449 return (game->lvlitems[dlevel]&(1 << li_compass))!=0;
1891
1892 default:
1893 if(it>=0&&it<MAXLEVELS)
1894 {
1895 return (game->lvlitems[it]&(1 << li_compass))!=0;
1896 }
1897
1898 break;
1899 }
1900 return 0;
1901 }
1902
1903 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1904 {
1905
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 195066 times.
195066 switch(it)
1906 {
1907 case -2:
1908 {
1909 for(int32_t i=0; i<MAXLEVELS; i++)
1910 {
1911 if(game->lvlitems[i]&(1 << li_boss_key))
1912 {
1913 return true;
1914 }
1915 }
1916
1917 return false;
1918 }
1919
1920 case -1:
1921 195066 return (game->lvlitems[dlevel]&(1 << li_boss_key))?1:0;
1922
1923 default:
1924 if(it>=0&&it<MAXLEVELS)
1925 {
1926 return (game->lvlitems[it]&(1 << li_boss_key))?1:0;
1927 }
1928 break;
1929 }
1930 return 0;
1931 }
1932
1933 default:
1934 int32_t itemid = getItemID(itemsbuf, item_type, it);
1935
1936 if(itemid == -1)
1937 return false;
1938
1939 return game->get_item(itemid);
1940 }
1941 43612664 }
1942
1943 150667964 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1944 {
1945
9/9
✓ Branch 0 taken 4421308 times.
✓ Branch 1 taken 115297500 times.
✓ Branch 2 taken 4421308 times.
✓ Branch 3 taken 4421308 times.
✓ Branch 4 taken 4421308 times.
✓ Branch 5 taken 4421308 times.
✓ Branch 6 taken 4421308 times.
✓ Branch 7 taken 4421308 times.
✓ Branch 8 taken 4421308 times.
150667964 switch(item_type)
1946 {
1947 case itype_clock:
1948 {
1949 4421308 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1950
1951
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4421308 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4421308 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1952 return itemsbuf[maxid].level;
1953
1954 4421308 return has_item(itype_clock,1) ? 1 : 0;
1955 }
1956
1957 case itype_key:
1958 4421308 return game->get_keys();
1959
1960 case itype_lkey:
1961 4421308 return game->lvlkeys[get_dlevel()];
1962
1963 case itype_magiccontainer:
1964 4421308 return game->get_maxmagic()/game->get_mp_per_block();
1965
1966 case itype_triforcepiece:
1967 {
1968 4421308 int count=0;
1969
1970
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int i=0; i<MAXLEVELS; i++)
1971 {
1972 2263709696 count+=(game->lvlitems[i]&(1 << li_mcguffin))?1:0;
1973 2263709696 }
1974
1975 4421308 return count;
1976 }
1977
1978 case itype_map:
1979 {
1980 4421308 int count=0;
1981
1982
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int i=0; i<MAXLEVELS; i++)
1983 {
1984 2263709696 count+=(game->lvlitems[i]&(1 << li_map))?1:0;
1985 2263709696 }
1986
1987 4421308 return count;
1988 }
1989
1990 case itype_compass:
1991 {
1992 4421308 int count=0;
1993
1994
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int i=0; i<MAXLEVELS; i++)
1995 {
1996 2263709696 count+=(game->lvlitems[i]&(1 << li_compass))?1:0;
1997 2263709696 }
1998
1999 4421308 return count;
2000 }
2001
2002 case itype_bosskey:
2003 {
2004 4421308 int count=0;
2005
2006
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int i=0; i<MAXLEVELS; i++)
2007 {
2008 2263709696 count+=(game->lvlitems[i]&(1 << li_boss_key))?1:0;
2009 2263709696 }
2010
2011 4421308 return count;
2012 }
2013
2014 default:
2015 115297500 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2016
2017
2/2
✓ Branch 0 taken 81896529 times.
✓ Branch 1 taken 33400971 times.
115297500 if(maxid == -1)
2018 81896529 return 0;
2019
2020 33400971 return itemsbuf[maxid].level;
2021 }
2022 150667964 }
2023
2024 418 std::map<int32_t, int32_t> itemcache;
2025 418 std::map<int32_t, int32_t> itemcache_cost;
2026
2027 void removeFromItemCache(int32_t itemclass)
2028 {
2029 itemcache.erase(itemclass);
2030 itemcache_cost.erase(itemclass);
2031 cache_tile_mod_clear();
2032 }
2033
2034 13061831 void flushItemCache(bool justcost)
2035 {
2036 13061831 itemcache_cost.clear();
2037
2/2
✓ Branch 0 taken 12988143 times.
✓ Branch 1 taken 73688 times.
13061831 if(!justcost)
2038 73688 itemcache.clear();
2039
2/2
✓ Branch 0 taken 6357348 times.
✓ Branch 1 taken 6630795 times.
12988143 else if(replay_version_check(0,19))
2040 6357348 return;
2041
2042 6704483 cache_tile_mod_clear();
2043
2044 //also fix the active subscreen if items were deleted -DD
2045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6704483 times.
6704483 if(game != NULL)
2046 {
2047 6704483 verifyBothWeapons();
2048 6704483 refresh_subscr_items();
2049 6704483 }
2050 13061831 }
2051
2052 // This is used often, so it should be as direct as possible.
2053 3049288617 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2054 {
2055 3049288617 bool use_cost_cache = replay_version_check(19);
2056
2/2
✓ Branch 0 taken 2909266079 times.
✓ Branch 1 taken 140022538 times.
3049288617 if(jinx_check)
2057 {
2058 //special case for shields...
2059
3/4
✓ Branch 0 taken 54404348 times.
✓ Branch 1 taken 85618190 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54404348 times.
140022538 if (itemtype == itype_shield && !HeroShieldClk())
2060 54404348 jinx_check = false;
2061
4/4
✓ Branch 0 taken 52679760 times.
✓ Branch 1 taken 32938430 times.
✓ Branch 2 taken 10934442 times.
✓ Branch 3 taken 41745318 times.
85618190 else if(!(HeroSwordClk() || HeroItemClk()))
2062 41745318 jinx_check = false; //not jinxed
2063 140022538 }
2064
4/4
✓ Branch 0 taken 121490 times.
✓ Branch 1 taken 3049167127 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 119637 times.
3049288617 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2065 3049168980 check_bunny = false;
2066
2/2
✓ Branch 0 taken 2991511971 times.
✓ Branch 1 taken 57776646 times.
3049288617 if(itemtype == itype_ring) checkmagic = true;
2067
4/4
✓ Branch 0 taken 3005415745 times.
✓ Branch 1 taken 43872872 times.
✓ Branch 2 taken 310572548 times.
✓ Branch 3 taken 25152461 times.
3385013626 if (!jinx_check && !check_bunny
2068
4/4
✓ Branch 0 taken 3005323716 times.
✓ Branch 1 taken 92029 times.
✓ Branch 2 taken 335725009 times.
✓ Branch 3 taken 2669598707 times.
3005415745 && (use_cost_cache || itemtype != itype_ring))
2069 {
2070
4/4
✓ Branch 0 taken 586650371 times.
✓ Branch 1 taken 2393520884 times.
✓ Branch 2 taken 260092074 times.
✓ Branch 3 taken 326558297 times.
2980171255 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2071 2980171255 auto res = cache.find(itemtype);
2072
2073
2/2
✓ Branch 0 taken 2829390255 times.
✓ Branch 1 taken 150781000 times.
2980171255 if(res != cache.end())
2074 2829390255 return res->second;
2075 150781000 }
2076
2077 219898362 int result = -1;
2078 219898362 int highestlevel = -1;
2079
2080
2/2
✓ Branch 0 taken 56293980672 times.
✓ Branch 1 taken 219898362 times.
56513879034 for(int i=0; i<MAXITEMS; i++)
2081 {
2082
6/6
✓ Branch 0 taken 6173553382 times.
✓ Branch 1 taken 50120427290 times.
✓ Branch 2 taken 96244962 times.
✓ Branch 3 taken 6077308420 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 96162914 times.
56293980672 if(game->get_item(i) && itemsbuf[i].type==itemtype && !item_disabled(i))
2083 {
2084
4/4
✓ Branch 0 taken 91488197 times.
✓ Branch 1 taken 4674717 times.
✓ Branch 2 taken 2473305 times.
✓ Branch 3 taken 89014892 times.
96162914 if(checkmagic && itemtype != itype_magicring)
2085
2/2
✓ Branch 0 taken 89014177 times.
✓ Branch 1 taken 715 times.
89014892 if(!checkmagiccost(i))
2086 715 continue;
2087
6/6
✓ Branch 0 taken 88703033 times.
✓ Branch 1 taken 7459166 times.
✓ Branch 2 taken 1257252 times.
✓ Branch 3 taken 6201914 times.
✓ Branch 4 taken 4066783 times.
✓ Branch 5 taken 3392383 times.
96162199 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3392383 times.
3392383 if(!(itemsbuf[i].flags & item_jinx_immune))
2089 3392383 continue;
2090
3/4
✓ Branch 0 taken 96967 times.
✓ Branch 1 taken 92672849 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96967 times.
92769816 if(check_bunny && !checkbunny(i))
2091 96967 continue;
2092
2093
2/2
✓ Branch 0 taken 8439007 times.
✓ Branch 1 taken 84233842 times.
92672849 if(itemsbuf[i].level >= highestlevel)
2094 {
2095 84233842 highestlevel = itemsbuf[i].level;
2096 84233842 result=i;
2097 84233842 }
2098 92672849 }
2099 56290490607 }
2100
2101
4/4
✓ Branch 0 taken 176025490 times.
✓ Branch 1 taken 43872872 times.
✓ Branch 2 taken 92029 times.
✓ Branch 3 taken 175933461 times.
219898362 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2102 {
2103
2/2
✓ Branch 0 taken 134165474 times.
✓ Branch 1 taken 41767987 times.
175933461 if (use_cost_cache)
2104 {
2105
2/2
✓ Branch 0 taken 118250684 times.
✓ Branch 1 taken 15914790 times.
134165474 if (!checkmagic)
2106 15914790 itemcache[itemtype] = result;
2107
6/6
✓ Branch 0 taken 15914790 times.
✓ Branch 1 taken 118250684 times.
✓ Branch 2 taken 688656 times.
✓ Branch 3 taken 15226134 times.
✓ Branch 4 taken 673653 times.
✓ Branch 5 taken 15003 times.
134165474 if (checkmagic || result < 0 || checkmagiccost(result))
2108 134150471 itemcache_cost[itemtype] = result;
2109 134165474 }
2110 else
2111 {
2112 41767987 itemcache[itemtype] = result;
2113 }
2114 175933461 }
2115 219898362 return result;
2116 3049288617 }
2117
2118 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2119 3022730802 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2120 {
2121
3/4
✓ Branch 0 taken 3005918209 times.
✓ Branch 1 taken 16812593 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3005918209 times.
3022730802 if(itype < 0 || itype >= itype_max) return -1;
2122
1/2
✓ Branch 0 taken 3005918209 times.
✗ Branch 1 not taken.
3005918209 if(game->OverrideItems[itype] > -2)
2123 {
2124 auto ovid = game->OverrideItems[itype];
2125 if(ovid < 0 || ovid >= MAXITEMS)
2126 return -1;
2127 if(itemsbuf[ovid].type == itype)
2128 {
2129 if(itype == itype_magicring)
2130 checkmagic = false;
2131 else if(itype == itype_ring)
2132 checkmagic = true;
2133
2134 if(checkmagic && !checkmagiccost(ovid))
2135 return -1;
2136
2137 if (jinx_check && !checkitem_jinx(ovid))
2138 {
2139 return -1;
2140 }
2141 return ovid;
2142 }
2143 }
2144 3005918209 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2145
2/2
✓ Branch 0 taken 96652130 times.
✓ Branch 1 taken 2909266079 times.
3005918209 if(!jinx_check) //If not already a jinx-immune-only check...
2146 {
2147 //And the player IS jinxed...
2148
2/2
✓ Branch 0 taken 2865895671 times.
✓ Branch 1 taken 43370408 times.
2909266079 if(HeroIsJinxed())
2149 {
2150 //Then do a jinx-immune-only check here
2151 43370408 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2152 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2153 //Should NOT need a compat rule, as this should always return -1 in old quests.
2154
2/2
✓ Branch 0 taken 3185264 times.
✓ Branch 1 taken 40185144 times.
43370408 if(ret2 > -1) return ret2;
2155 40185144 }
2156 2906080815 }
2157 3002732945 return ret;
2158 3022730802 }
2159
2160 66341875 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2161 {
2162 66341875 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2163
2/2
✓ Branch 0 taken 35534481 times.
✓ Branch 1 taken 30807394 times.
66341875 return (result<0) ? 0 : itemsbuf[result].power;
2164 }
2165
2166 26 int32_t heart_container_id()
2167 {
2168
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2169 {
2170
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].type == itype_heartcontainer)
2171 {
2172 26 return i;
2173 }
2174 728 }
2175 return -1;
2176 26 }
2177
2178 struct tilemod_cache_state_t
2179 {
2180
6/6
✓ Branch 0 taken 4420952 times.
✓ Branch 1 taken 8543212 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8543210 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8542856 times.
21507376 bool operator==(const tilemod_cache_state_t&) const = default;
2181
2182 bool valid;
2183 bool bunny_clock;
2184 bool superman;
2185 int shield;
2186 };
2187 tilemod_cache_state_t tilemod_cache_state;
2188 int32_t tilemod_cache_value;
2189
2190 6706040 void cache_tile_mod_clear()
2191 {
2192 6706040 tilemod_cache_state = {false};
2193 6706040 }
2194
2195 12964164 int32_t item_tile_mod()
2196 {
2197 51856656 tilemod_cache_state_t state = {
2198 .valid = true,
2199 12964164 .bunny_clock = Hero.BunnyClock() != 0,
2200 12964164 .superman = Hero.superman,
2201 12964164 .shield = Hero.active_shield_id,
2202 };
2203
2/2
✓ Branch 0 taken 8542856 times.
✓ Branch 1 taken 4421308 times.
12964164 if (tilemod_cache_state == state)
2204 8542856 return tilemod_cache_value;
2205
2206 4421308 int32_t tile=0;
2207 4421308 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2208
4/4
✓ Branch 0 taken 4007992 times.
✓ Branch 1 taken 413316 times.
✓ Branch 2 taken 3079194 times.
✓ Branch 3 taken 928798 times.
4421308 if(check_bombcost || game->get_bombs())
2209 {
2210 3492510 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2211
3/4
✓ Branch 0 taken 3432971 times.
✓ Branch 1 taken 59539 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3432971 times.
3492510 if(itemid > -1 && checkbunny(itemid))
2212 3432971 tile+=itemsbuf[itemid].ltm;
2213 3492510 }
2214
2215
4/4
✓ Branch 0 taken 4007992 times.
✓ Branch 1 taken 413316 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3042694 times.
4421308 if(check_bombcost || game->get_sbombs())
2216 {
2217 1378614 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2218
3/4
✓ Branch 0 taken 965057 times.
✓ Branch 1 taken 413557 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 965057 times.
1378614 if(itemid > -1 && checkbunny(itemid))
2219 965057 tile+=itemsbuf[itemid].ltm;
2220 1378614 }
2221
2222
2/2
✓ Branch 0 taken 4408572 times.
✓ Branch 1 taken 12736 times.
4421308 if(current_item(itype_clock))
2223 {
2224 12736 int32_t itemid =
2225
2/2
✓ Branch 0 taken 12704 times.
✓ Branch 1 taken 32 times.
12736 get_qr(qr_HARDCODED_LITEM_LTMS)
2226 ? iClock
2227 32 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2228
2/4
✓ Branch 0 taken 12736 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12736 times.
12736 if(itemid > -1 && checkbunny(itemid))
2229 12736 tile+=itemsbuf[itemid].ltm;
2230 12736 }
2231
2232
2/2
✓ Branch 0 taken 3775666 times.
✓ Branch 1 taken 645642 times.
4421308 if(current_item(itype_key))
2233 {
2234 645642 int32_t itemid =
2235
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2236 ? iKey
2237 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2238
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2239 645642 tile+=itemsbuf[itemid].ltm;
2240 645642 }
2241
2242
2/2
✓ Branch 0 taken 3920424 times.
✓ Branch 1 taken 500884 times.
4421308 if(current_item(itype_lkey))
2243 {
2244 500884 int32_t itemid =
2245
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 86715 times.
500884 get_qr(qr_HARDCODED_LITEM_LTMS)
2246 ? iLevelKey
2247 86715 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2248
2/4
✓ Branch 0 taken 500884 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500884 times.
500884 if(itemid > -1 && checkbunny(itemid))
2249 500884 tile+=itemsbuf[itemid].ltm;
2250 500884 }
2251
2252
2/2
✓ Branch 0 taken 1586478 times.
✓ Branch 1 taken 2834830 times.
4421308 if(current_item(itype_map))
2253 {
2254 2834830 int32_t itemid =
2255
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10996 times.
2834830 get_qr(qr_HARDCODED_LITEM_LTMS)
2256 ? iMap
2257 10996 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2258
2/4
✓ Branch 0 taken 2834830 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834830 times.
2834830 if(itemid > -1 && checkbunny(itemid))
2259 2834830 tile+=itemsbuf[itemid].ltm;
2260 2834830 }
2261
2262
2/2
✓ Branch 0 taken 2109319 times.
✓ Branch 1 taken 2311989 times.
4421308 if(current_item(itype_compass))
2263 {
2264 2311989 int32_t itemid =
2265
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2266 ? iCompass
2267 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2268
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2269 2311989 tile+=itemsbuf[itemid].ltm;
2270 2311989 }
2271
2272
2/2
✓ Branch 0 taken 1334892 times.
✓ Branch 1 taken 3086416 times.
4421308 if(current_item(itype_bosskey))
2273 {
2274 3086416 int32_t itemid =
2275
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2276 ? iBossKey
2277 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2278
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2279 3086416 tile+=itemsbuf[itemid].ltm;
2280 3086416 }
2281
2282
2/2
✓ Branch 0 taken 48314 times.
✓ Branch 1 taken 4372994 times.
4421308 if(current_item(itype_magiccontainer))
2283 {
2284 4372994 int32_t itemid =
2285
2/2
✓ Branch 0 taken 3904336 times.
✓ Branch 1 taken 468658 times.
4372994 get_qr(qr_HARDCODED_LITEM_LTMS)
2286 ? iMagicC
2287 468658 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2288
3/4
✓ Branch 0 taken 4372994 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4372977 times.
4372994 if(itemid > -1 && checkbunny(itemid))
2289 4372977 tile+=itemsbuf[itemid].ltm;
2290 4372994 }
2291
2292
2/2
✓ Branch 0 taken 1314828 times.
✓ Branch 1 taken 3106480 times.
4421308 if(current_item(itype_triforcepiece))
2293 {
2294 3106480 int32_t itemid =
2295
2/2
✓ Branch 0 taken 3069478 times.
✓ Branch 1 taken 37002 times.
3106480 get_qr(qr_HARDCODED_LITEM_LTMS)
2296 ? iTriforce
2297 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2298
2/4
✓ Branch 0 taken 3106480 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3106480 times.
3106480 if(itemid > -1 && checkbunny(itemid))
2299 3106480 tile+=itemsbuf[itemid].ltm;
2300 3106480 }
2301
2302
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int32_t i=0; i<itype_max; i++)
2303 {
2304
2/2
✓ Branch 0 taken 2023628800 times.
✓ Branch 1 taken 240080896 times.
2263709696 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2305 {
2306
2/2
✓ Branch 0 taken 4689080 times.
✓ Branch 1 taken 235391816 times.
240080896 switch(i)
2307 {
2308 case itype_bomb:
2309 case itype_sbomb:
2310 case itype_clock:
2311 case itype_key:
2312 case itype_lkey:
2313 case itype_map:
2314 case itype_compass:
2315 case itype_bosskey:
2316 case itype_magiccontainer:
2317 case itype_triforcepiece:
2318 4689080 continue; //already handled
2319 }
2320 235391816 }
2321 2259020616 int32_t itemid = current_item_id(i,false);
2322
2/2
✓ Branch 0 taken 2254599308 times.
✓ Branch 1 taken 4421308 times.
2259020616 if(i == itype_shield)
2323 4421308 itemid = getCurrentShield(false);
2324
2325
4/4
✓ Branch 0 taken 115677585 times.
✓ Branch 1 taken 2143343031 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 115677584 times.
2259020616 if(itemid < 0 || !checkbunny(itemid))
2326 2143343032 continue;
2327
2328 115677584 itemdata const& itm = itemsbuf[itemid];
2329
2330
2/2
✓ Branch 0 taken 111976863 times.
✓ Branch 1 taken 3700721 times.
115677584 switch(itm.type)
2331 {
2332 case itype_shield:
2333
1/2
✓ Branch 0 taken 3700721 times.
✗ Branch 1 not taken.
3700721 if(itm.flags & item_flag9) //active shield
2334 {
2335 if(!usingActiveShield(itemid))
2336 {
2337 tile+=itm.misc6; //'Inactive PTM'
2338 continue;
2339 }
2340 }
2341 3700721 break;
2342 }
2343
2344 115677584 tile+=itm.ltm;
2345 115677584 }
2346
2347 4421308 tilemod_cache_value = tile;
2348 4421308 tilemod_cache_state = state;
2349 4421308 return tile;
2350 12964164 }
2351
2352 12964164 int32_t bunny_tile_mod()
2353 {
2354
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12962294 times.
12964164 if(Hero.BunnyClock())
2355 {
2356 1870 return game->get_bunny_ltm();
2357 }
2358 12962294 return 0;
2359 12964164 }
2360
2361 // Hints are drawn on a separate layer to combo reveals.
2362 // TODO: move out of zc_sys.cpp, weird place for this code.
2363 20058 void draw_lens_under(BITMAP *dest, bool layer)
2364 {
2365 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2366 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2367 //Lens flag 3: Don't show armos/chest/dive items
2368 //Lens flag 4: Show Raft Paths
2369 //Lens flag 5: Show Invisible Enemies
2370
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2371
2372 20058 int32_t strike_hint_table[11]=
2373 {
2374 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2375 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2376 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2377 };
2378
2379 {
2380 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2381 20058 int32_t tempitem, tempweapon=0;
2382 20058 strike_hint=strike_hint_table[strike_hint_counter];
2383
2384
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2385 {
2386 599 strike_hint_timer=0;
2387 599 strike_hint_counter=((strike_hint_counter+1)%11);
2388 599 }
2389
2390 20058 ++strike_hint_timer;
2391
2392 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2393 3530208 mapscr* scr = rpos_handle.scr;
2394 7306676 auto [x, y] = rpos_handle.xy();
2395 7060416 y += playing_field_offset;
2396
2397 3530208 int32_t tempitemx=-16, tempitemy=-16;
2398 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2399
2400
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2401 {
2402 7060416 int32_t checkflag=0;
2403
2404
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2405 {
2406 3530208 checkflag = rpos_handle.cflag();
2407 3530208 }
2408 else
2409 {
2410 3530208 checkflag = rpos_handle.sflag();
2411 }
2412
2413
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2414 {
2415
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2416 {
2417
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2418 906 }
2419 else
2420 {
2421 192 checkflag = strike_hint;
2422 }
2423 1098 }
2424
2425
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2426 {
2427 case 0:
2428 case mfZELDA:
2429 case mfPUSHED:
2430 case mfENEMY0:
2431 case mfENEMY1:
2432 case mfENEMY2:
2433 case mfENEMY3:
2434 case mfENEMY4:
2435 case mfENEMY5:
2436 case mfENEMY6:
2437 case mfENEMY7:
2438 case mfENEMY8:
2439 case mfENEMY9:
2440 case mfSINGLE:
2441 case mfSINGLE16:
2442 case mfNOENEMY:
2443 case mfTRAP_H:
2444 case mfTRAP_V:
2445 case mfTRAP_4:
2446 case mfTRAP_LR:
2447 case mfTRAP_UD:
2448 case mfNOGROUNDENEMY:
2449 case mfNOBLOCKS:
2450 case mfSCRIPT1:
2451 case mfSCRIPT2:
2452 case mfSCRIPT3:
2453 case mfSCRIPT4:
2454 case mfSCRIPT5:
2455 case mfSCRIPT6:
2456 case mfSCRIPT7:
2457 case mfSCRIPT8:
2458 case mfSCRIPT9:
2459 case mfSCRIPT10:
2460 case mfSCRIPT11:
2461 case mfSCRIPT12:
2462 case mfSCRIPT13:
2463 case mfSCRIPT14:
2464 case mfSCRIPT15:
2465 case mfSCRIPT16:
2466 case mfSCRIPT17:
2467 case mfSCRIPT18:
2468 case mfSCRIPT19:
2469 case mfSCRIPT20:
2470 case mfPITHOLE:
2471 case mfPITFALLFLOOR:
2472 case mfLAVA:
2473 case mfICE:
2474 case mfICEDAMAGE:
2475 case mfDAMAGE1:
2476 case mfDAMAGE2:
2477 case mfDAMAGE4:
2478 case mfDAMAGE8:
2479 case mfDAMAGE16:
2480 case mfDAMAGE32:
2481 case mfFREEZEALL:
2482 case mfFREZEALLANSFFCS:
2483 case mfFREEZEFFCSOLY:
2484 case mfSCRITPTW1TRIG:
2485 case mfSCRITPTW2TRIG:
2486 case mfSCRITPTW3TRIG:
2487 case mfSCRITPTW4TRIG:
2488 case mfSCRITPTW5TRIG:
2489 case mfSCRITPTW6TRIG:
2490 case mfSCRITPTW7TRIG:
2491 case mfSCRITPTW8TRIG:
2492 case mfSCRITPTW9TRIG:
2493 case mfSCRITPTW10TRIG:
2494 case mfTROWEL:
2495 case mfTROWELNEXT:
2496 case mfTROWELSPECIALITEM:
2497 case mfSLASHPOT:
2498 case mfLIFTPOT:
2499 case mfLIFTORSLASH:
2500 case mfLIFTROCK:
2501 case mfLIFTROCKHEAVY:
2502 case mfDROPITEM:
2503 case mfSPECIALITEM:
2504 case mfDROPKEY:
2505 case mfDROPLKEY:
2506 case mfDROPCOMPASS:
2507 case mfDROPMAP:
2508 case mfDROPBOSSKEY:
2509 case mfSPAWNNPC:
2510 case mfSWITCHHOOK:
2511 case mfSIDEVIEWLADDER:
2512 case mfSIDEVIEWPLATFORM:
2513 case mfNOENEMYSPAWN:
2514 case mfENEMYALL:
2515 case mfNOMIRROR:
2516 case mfUNSAFEGROUND:
2517 case mf168:
2518 case mf169:
2519 case mf170:
2520 case mf171:
2521 case mf172:
2522 case mf173:
2523 case mf174:
2524 case mf175:
2525 case mf176:
2526 case mf177:
2527 case mf178:
2528 case mf179:
2529 case mf180:
2530 case mf181:
2531 case mf182:
2532 case mf183:
2533 case mf184:
2534 case mf185:
2535 case mf186:
2536 case mf187:
2537 case mf188:
2538 case mf189:
2539 case mf190:
2540 case mf191:
2541 case mf192:
2542 case mf193:
2543 case mf194:
2544 case mf195:
2545 case mf196:
2546 case mf197:
2547 case mf198:
2548 case mf199:
2549 case mf200:
2550 case mf201:
2551 case mf202:
2552 case mf203:
2553 case mf204:
2554 case mf205:
2555 case mf206:
2556 case mf207:
2557 case mf208:
2558 case mf209:
2559 case mf210:
2560 case mf211:
2561 case mf212:
2562 case mf213:
2563 case mf214:
2564 case mf215:
2565 case mf216:
2566 case mf217:
2567 case mf218:
2568 case mf219:
2569 case mf220:
2570 case mf221:
2571 case mf222:
2572 case mf223:
2573 case mf224:
2574 case mf225:
2575 case mf226:
2576 case mf227:
2577 case mf228:
2578 case mf229:
2579 case mf230:
2580 case mf231:
2581 case mf232:
2582 case mf233:
2583 case mf234:
2584 case mf235:
2585 case mf236:
2586 case mf237:
2587 case mf238:
2588 case mf239:
2589 case mf240:
2590 case mf241:
2591 case mf242:
2592 case mf243:
2593 case mf244:
2594 case mf245:
2595 case mf246:
2596 case mf247:
2597 case mf248:
2598 case mf249:
2599 case mf250:
2600 case mf251:
2601 case mf252:
2602 case mf253:
2603 case mf254:
2604 case mfEXTENDED:
2605 6911766 break;
2606
2607 case mfPUSHUD:
2608 case mfPUSHLR:
2609 case mfPUSH4:
2610 case mfPUSHU:
2611 case mfPUSHD:
2612 case mfPUSHL:
2613 case mfPUSHR:
2614 case mfPUSHUDNS:
2615 case mfPUSHLRNS:
2616 case mfPUSH4NS:
2617 case mfPUSHUNS:
2618 case mfPUSHDNS:
2619 case mfPUSHLNS:
2620 case mfPUSHRNS:
2621 case mfPUSHUDINS:
2622 case mfPUSHLRINS:
2623 case mfPUSH4INS:
2624 case mfPUSHUINS:
2625 case mfPUSHDINS:
2626 case mfPUSHLINS:
2627 case mfPUSHRINS:
2628
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2629
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2630 {
2631 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2632 }
2633
2634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2635
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2636 {
2637
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2638 {
2639
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2640 {
2641 case cPUSH_HEAVY:
2642 case cPUSH_HW:
2643 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2644 144 tempitemx=x, tempitemy=y;
2645
2646
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2647 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2648
2649 72 break;
2650
2651 case cPUSH_HEAVY2:
2652 case cPUSH_HW2:
2653 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2654 126 tempitemx=x, tempitemy=y;
2655
2656
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2657 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2658
2659 63 break;
2660 }
2661 1032 }
2662 2520 }
2663
2664 3258 break;
2665
2666 case mfWHISTLE:
2667
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2668 {
2669 tempitem=getItemID(itemsbuf,itype_whistle,1);
2670
2671 if(tempitem<0) break;
2672
2673 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2674 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2675 {
2676 tempitemx=x;
2677 tempitemy=y;
2678 }
2679
2680 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2681 }
2682
2683 2418 break;
2684
2685 //Why is this here?
2686 case mfFAIRY:
2687 case mfMAGICFAIRY:
2688 case mfALLFAIRY:
2689 if(hints)
2690 {
2691 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2692
2693 if(tempitem < 0) break;
2694
2695 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2696 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2697 {
2698 tempitemx=x;
2699 tempitemy=y;
2700 }
2701
2702 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2703 }
2704
2705 break;
2706
2707 case mfANYFIRE:
2708
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2709 {
2710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2711 252 }
2712 else
2713 {
2714 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2715
2716
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2717
2718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2719
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2720 {
2721 189 tempitemx=x;
2722 189 tempitemy=y;
2723 189 }
2724
2725 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2726 }
2727
2728 504 break;
2729
2730 case mfSTRONGFIRE:
2731 if(!hints)
2732 {
2733 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2734 }
2735 else
2736 {
2737 tempitem=getItemID(itemsbuf,itype_candle,2);
2738
2739 if(tempitem<0) break;
2740
2741 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2742 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2743 {
2744 tempitemx=x;
2745 tempitemy=y;
2746 }
2747
2748 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2749 }
2750
2751 break;
2752
2753 case mfMAGICFIRE:
2754 if(!hints)
2755 {
2756 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2757 }
2758 else
2759 {
2760 tempitem=getItemID(itemsbuf,itype_wand,1);
2761
2762 if(tempitem<0) break;
2763
2764 tempweapon=wFire;
2765
2766 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2767 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2768 {
2769 tempitemx=x;
2770 tempitemy=y;
2771 }
2772 else
2773 {
2774 tempweaponx=x;
2775 tempweapony=y;
2776 }
2777
2778 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2779 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2780 }
2781
2782 break;
2783
2784 case mfDIVINEFIRE:
2785 if(!hints)
2786 {
2787 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2788 }
2789 else
2790 {
2791 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2792
2793 if(tempitem<0) break;
2794
2795 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2796 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2797 {
2798 tempitemx=x;
2799 tempitemy=y;
2800 }
2801
2802 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2803 }
2804
2805 break;
2806
2807 case mfARROW:
2808
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2809 {
2810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2811 732 }
2812 else
2813 {
2814 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2815
2816
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2817
2818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2819
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2820 {
2821 61 tempitemx=x;
2822 61 tempitemy=y;
2823 61 }
2824
2825 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2826 }
2827
2828 814 break;
2829
2830 case mfSARROW:
2831 if(!hints)
2832 {
2833 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2834 }
2835 else
2836 {
2837 tempitem=getItemID(itemsbuf,itype_arrow,2);
2838
2839 if(tempitem<0) break;
2840
2841 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2842 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2843 {
2844 tempitemx=x;
2845 tempitemy=y;
2846 }
2847
2848 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2849 }
2850
2851 break;
2852
2853 case mfGARROW:
2854 if(!hints)
2855 {
2856 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2857 }
2858 else
2859 {
2860 tempitem=getItemID(itemsbuf,itype_arrow,3);
2861
2862 if(tempitem<0) break;
2863
2864 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2865 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2866 {
2867 tempitemx=x;
2868 tempitemy=y;
2869 }
2870
2871 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2872 }
2873
2874 break;
2875
2876 case mfBOMB:
2877
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2878 {
2879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2880 76 }
2881 else
2882 {
2883 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2884 17 tempweapon = wLitBomb;
2885
2886 //if (tempitem<0) break;
2887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2888
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2889 {
2890 12 tempweaponx=x;
2891 12 tempweapony=y;
2892 12 }
2893
2894 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2895 }
2896
2897 93 break;
2898
2899 case mfSBOMB:
2900
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2901 {
2902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2903 48 }
2904 else
2905 {
2906 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2907 //if (tempitem<0) break;
2908 48 tempweapon = wLitSBomb;
2909
2910
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2911
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2912 {
2913 36 tempweaponx=x;
2914 36 tempweapony=y;
2915 36 }
2916
2917 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2918 }
2919
2920 96 break;
2921
2922 case mfARMOS_SECRET:
2923
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2924 {
2925
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2926 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2927 12 }
2928 24 break;
2929
2930 case mfBRANG:
2931
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2932 {
2933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2934 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2935 20 }
2936 else
2937 {
2938 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2939
2940
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2941
2942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2943
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2944 {
2945 4 tempitemx=x;
2946 4 tempitemy=y;
2947 4 }
2948
2949 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2950 }
2951
2952 25 break;
2953
2954 case mfMBRANG:
2955 if(!hints)
2956 {
2957 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2958 }
2959 else
2960 {
2961 tempitem=getItemID(itemsbuf,itype_brang,2);
2962
2963 if(tempitem<0) break;
2964
2965 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2966 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2967 {
2968 tempitemx=x;
2969 tempitemy=y;
2970 }
2971
2972 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2973 }
2974
2975 break;
2976
2977 case mfFBRANG:
2978 if(!hints)
2979 {
2980 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2981 }
2982 else
2983 {
2984 tempitem=getItemID(itemsbuf,itype_brang,3);
2985
2986 if(tempitem<0) break;
2987
2988 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2989 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2990 {
2991 tempitemx=x;
2992 tempitemy=y;
2993 }
2994
2995 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2996 }
2997
2998 break;
2999
3000 case mfWANDMAGIC:
3001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
3002 {
3003
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
3004 138 }
3005 else
3006 {
3007 tempitem=getItemID(itemsbuf,itype_wand,1);
3008
3009 if(tempitem<0) break;
3010
3011 tempweapon=itemsbuf[tempitem].wpn3;
3012
3013 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3014 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3015 {
3016 tempitemx=x;
3017 tempitemy=y;
3018 }
3019 else
3020 {
3021 tempweaponx=x;
3022 tempweapony=y;
3023 --lens_hint_weapon[wMagic][4];
3024
3025 if(lens_hint_weapon[wMagic][4]<-8)
3026 {
3027 lens_hint_weapon[wMagic][4]=8;
3028 }
3029 }
3030
3031 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3032 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3033 }
3034
3035 138 break;
3036
3037 case mfREFMAGIC:
3038
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3039 {
3040 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3041 }
3042 else
3043 {
3044 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3045
3046
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3047
3048 16 tempweapon=ewMagic;
3049
3050
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3051
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3052 {
3053 13 tempitemx=x;
3054 13 tempitemy=y;
3055 13 }
3056 else
3057 {
3058 3 tempweaponx=x;
3059 3 tempweapony=y;
3060
3061
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3062 {
3063 1 --lens_hint_weapon[ewMagic][4];
3064 1 }
3065 else
3066 {
3067 2 ++lens_hint_weapon[ewMagic][4];
3068 }
3069
3070
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3071 {
3072 lens_hint_weapon[ewMagic][2]=up;
3073 }
3074
3075
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3076 {
3077 2 lens_hint_weapon[ewMagic][2]=down;
3078 2 }
3079 }
3080
3081 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3082 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3083 }
3084
3085 16 break;
3086
3087 case mfREFFIREBALL:
3088
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3089 {
3090 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3091 }
3092 else
3093 {
3094 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3095
3096
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3097
3098 16 tempweapon=ewFireball;
3099
3100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3101
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3102 {
3103 12 tempitemx=x;
3104 12 tempitemy=y;
3105 12 tempweaponx=x;
3106 12 tempweapony=y;
3107 12 ++lens_hint_weapon[ewFireball][3];
3108
3109
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3110 {
3111 1 lens_hint_weapon[ewFireball][3]=-8;
3112 1 lens_hint_weapon[ewFireball][4]=8;
3113 1 }
3114
3115
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3116 {
3117 8 ++lens_hint_weapon[ewFireball][4];
3118 8 }
3119 else
3120 {
3121 4 --lens_hint_weapon[ewFireball][4];
3122 }
3123 12 }
3124
3125 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3126 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3127 }
3128
3129 16 break;
3130
3131 case mfSWORD:
3132
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3133 {
3134 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3135 }
3136 else
3137 {
3138 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3139
3140
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3141
3142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3143
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3144 {
3145 5 tempitemx=x;
3146 5 tempitemy=y;
3147 5 }
3148
3149 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3150 }
3151
3152 7 break;
3153
3154 case mfWSWORD:
3155 if(!hints)
3156 {
3157 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3158 }
3159 else
3160 {
3161 tempitem=getItemID(itemsbuf,itype_sword,2);
3162
3163 if(tempitem<0) break;
3164
3165 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3166 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3167 {
3168 tempitemx=x;
3169 tempitemy=y;
3170 }
3171
3172 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3173 }
3174
3175 break;
3176
3177 case mfMSWORD:
3178 if(!hints)
3179 {
3180 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3181 }
3182 else
3183 {
3184 tempitem=getItemID(itemsbuf,itype_sword,3);
3185
3186 if(tempitem<0) break;
3187
3188 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3189 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3190 {
3191 tempitemx=x;
3192 tempitemy=y;
3193 }
3194
3195 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3196 }
3197
3198 break;
3199
3200 case mfXSWORD:
3201 if(!hints)
3202 {
3203 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3204 }
3205 else
3206 {
3207 tempitem=getItemID(itemsbuf,itype_sword,4);
3208
3209 if(tempitem<0) break;
3210
3211 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3212 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3213 {
3214 tempitemx=x;
3215 tempitemy=y;
3216 }
3217
3218 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3219 }
3220
3221 break;
3222
3223 case mfSWORDBEAM:
3224
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3225 {
3226 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3227 }
3228 else
3229 {
3230 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3231
3232
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3233
3234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3235
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3236 {
3237 11 tempitemx=x;
3238 11 tempitemy=y;
3239 11 }
3240
3241 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3242 }
3243
3244 16 break;
3245
3246 case mfWSWORDBEAM:
3247 if(!hints)
3248 {
3249 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3250 }
3251 else
3252 {
3253 tempitem=getItemID(itemsbuf,itype_sword,2);
3254
3255 if(tempitem<0) break;
3256
3257 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3259 {
3260 tempitemx=x;
3261 tempitemy=y;
3262 }
3263
3264 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3265 }
3266
3267 break;
3268
3269 case mfMSWORDBEAM:
3270 if(!hints)
3271 {
3272 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3273 }
3274 else
3275 {
3276 tempitem=getItemID(itemsbuf,itype_sword,3);
3277
3278 if(tempitem<0) break;
3279
3280 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3281 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3282 {
3283 tempitemx=x;
3284 tempitemy=y;
3285 }
3286
3287 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3288 }
3289
3290 break;
3291
3292 case mfXSWORDBEAM:
3293 if(!hints)
3294 {
3295 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3296 }
3297 else
3298 {
3299 tempitem=getItemID(itemsbuf,itype_sword,4);
3300
3301 if(tempitem<0) break;
3302
3303 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3304 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3305 {
3306 tempitemx=x;
3307 tempitemy=y;
3308 }
3309
3310 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3311 }
3312
3313 break;
3314
3315 case mfHOOKSHOT:
3316
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3317 {
3318 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3319 }
3320 else
3321 {
3322 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3323
3324
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3325
3326
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3327
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3328 {
3329 12 tempitemx=x;
3330 12 tempitemy=y;
3331 12 }
3332
3333 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3334 }
3335
3336 17 break;
3337
3338 case mfWAND:
3339
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3340 {
3341 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3342 }
3343 else
3344 {
3345 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3346
3347
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3348
3349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3350
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3351 {
3352 28 tempitemx=x;
3353 28 tempitemy=y;
3354 28 }
3355
3356 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3357 }
3358
3359 35 break;
3360
3361 case mfHAMMER:
3362
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3363 {
3364 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3365 }
3366 else
3367 {
3368 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3369
3370
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3371
3372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3373
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3374 {
3375 13 tempitemx=x;
3376 13 tempitemy=y;
3377 13 }
3378
3379 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3380 }
3381
3382 17 break;
3383
3384 case mfARMOS_ITEM:
3385 case mfDIVE_ITEM:
3386 {
3387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
2602 int flag = (cur_screen < 128 && get_qr(qr_ITEMPICKUPSETSBELOW)) ? mITEM : mSPECIALITEM;
3388
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, flag) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3389 {
3390 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3391 2602 }
3392 2602 break;
3393 }
3394
3395 case 16:
3396 case 17:
3397 case 18:
3398 case 19:
3399 case 20:
3400 case 21:
3401 case 22:
3402 case 23:
3403 case 24:
3404 case 25:
3405 case 26:
3406 case 27:
3407 case 28:
3408 case 29:
3409 case 30:
3410 case 31:
3411
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3413 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3414
3415 108898 break;
3416 case mfSECRETSNEXT:
3417 if(!hints)
3418 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3419 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3420
3421 break;
3422
3423 case mfSTRIKE:
3424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3425 {
3426 906 goto special;
3427 }
3428 else
3429 {
3430 break;
3431 }
3432
3433 28750 default: goto special;
3434
3435 special:
3436
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3437 {
3438
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3439 {
3440 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3441 4954 }
3442 6604 }
3443
3444 29656 break;
3445 }
3446 7060416 }
3447 3530208 });
3448
3449 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3450 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3451
3452 40116 offx -= viewport.x;
3453 40116 offy -= viewport.y;
3454 40116 offy += playing_field_offset;
3455
3456
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3457 {
3458
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3459 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3460
3461
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3462 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3463
3464
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3465 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3466
3467
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3468 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3469
3470
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3471 {
3472 129 showbombeddoor(scr, dest, 0, offx, offy);
3473 43 }
3474
3475
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3476 {
3477 117 showbombeddoor(scr, dest, 1, offx, offy);
3478 39 }
3479
3480
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3481 {
3482 18 showbombeddoor(scr, dest, 2, offx, offy);
3483 6 }
3484
3485
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3486 {
3487 111 showbombeddoor(scr, dest, 3, offx, offy);
3488 37 }
3489 10029 }
3490
3491
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3492 {
3493
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3494 {
3495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3496 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3497 1123 }
3498 else
3499 {
3500
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3501 {
3502 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3503 48 int32_t tempitemx=-16+offx;
3504 48 int32_t tempitemy=-16+offy-playing_field_offset;
3505
3506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3507
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3508 {
3509 48 tempitemx=scr->stairx+offx;
3510 48 tempitemy=scr->stairy+offy;
3511 24 }
3512
3513 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3514 48 }
3515 }
3516 2034 }
3517 20058 });
3518 }
3519 20058 }
3520
3521 9690 void draw_lens_over()
3522 {
3523 9690 int w = 288;
3524 9690 int h = 240;
3525
3526
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3527 static int32_t last_width = -1;
3528 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3529
3530 // Only redraw the circle if the size has changed
3531
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3532 {
3533 20 clear_to_color(lens_scr, BLACK);
3534 20 circlefill(lens_scr, w, h, width, 0);
3535 20 circle(lens_scr, w, h, width+2, 0);
3536 20 circle(lens_scr, w, h, width+5, 0);
3537 20 last_width=width;
3538 20 }
3539
3540 9690 masked_blit(lens_scr, framebuf, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3541 9690 do_primitives(framebuf, SPLAYER_LENS_OVER);
3542 9690 }
3543
3544 37086070 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3545 {
3546 37086070 BITMAP* bmp = *bmp_ptr;
3547
3/4
✓ Branch 0 taken 37086070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37086064 times.
✓ Branch 3 taken 6 times.
37086070 if (bmp->w == w && bmp->h == h)
3548 37086064 return;
3549
3550 6 int depth = bitmap_color_depth(bmp);
3551 6 destroy_bitmap(bmp);
3552 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3553 37086070 }
3554
3555 32028 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3556 {
3557
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 32022 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
32028 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3558 32028 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3559
3560 32028 clear_to_color(wavebuf, BLACK);
3561 32028 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3562
3563 int32_t ofs;
3564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32028 times.
32028 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3565
4/6
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
✓ Branch 4 taken 606 times.
✓ Branch 5 taken 31422 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3566 32028 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3567
2/4
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3568 32028 int32_t i=frame%amp2;
3569
3570
2/2
✓ Branch 0 taken 5382552 times.
✓ Branch 1 taken 32028 times.
5414580 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3571 {
3572
3/4
✓ Branch 0 taken 2691276 times.
✓ Branch 1 taken 2691276 times.
✓ Branch 2 taken 2691276 times.
✗ Branch 3 not taken.
5382552 if(j&1 && interpol)
3573 {
3574 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3575 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3576 }
3577 else
3578 {
3579 5382552 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3580 }
3581
3582
1/2
✓ Branch 0 taken 5382552 times.
✗ Branch 1 not taken.
5382552 if(ofs)
3583 {
3584
2/2
✓ Branch 0 taken 1377933312 times.
✓ Branch 1 taken 5382552 times.
1383315864 for(int32_t k=0; k<256; k++)
3585 {
3586 1377933312 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3587 1377933312 }
3588 5382552 }
3589 5382552 }
3590 32028 }
3591
3592 28272 void draw_fuzzy(int32_t fuzz)
3593 // draws from right half of scrollbuf to framebuf
3594 {
3595 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3596 byte *start, *si, *di;
3597
3598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28272 times.
28272 if(fuzz<1)
3599 fuzz = 1;
3600
3601 28272 xstep = 128%fuzz;
3602
3603
2/2
✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 22382 times.
28272 if(xstep > 0)
3604 22382 xstep = fuzz-xstep;
3605
3606 28272 ystep = 112%fuzz;
3607
3608
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 20026 times.
28272 if(ystep > 0)
3609 20026 ystep = fuzz-ystep;
3610
3611 28272 firsty = 1;
3612
3613
2/2
✓ Branch 0 taken 28272 times.
✓ Branch 1 taken 1020148 times.
1048420 for(y=0; y<framebuf->h;)
3614 {
3615 1020148 start = &(scrollbuf_old->line[y][256]);
3616
3617
4/4
✓ Branch 0 taken 1006012 times.
✓ Branch 1 taken 6347064 times.
✓ Branch 2 taken 6332928 times.
✓ Branch 3 taken 1020148 times.
7353076 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3618 {
3619 6332928 si = start;
3620 6332928 di = &(framebuf->line[y+dy][0]);
3621 6332928 i = xstep;
3622 6332928 firstx = 1;
3623
3624
2/2
✓ Branch 0 taken 1621229568 times.
✓ Branch 1 taken 6332928 times.
1627562496 for(dx=0; dx<framebuf->w; dx++)
3625 {
3626 1621229568 *(di++) = *si;
3627
3628
2/2
✓ Branch 0 taken 1366065344 times.
✓ Branch 1 taken 255164224 times.
1621229568 if(++i >= fuzz)
3629 {
3630
2/2
✓ Branch 0 taken 248831296 times.
✓ Branch 1 taken 6332928 times.
255164224 if(!firstx)
3631 248831296 si += fuzz;
3632 else
3633 {
3634 6332928 si += fuzz-xstep;
3635 6332928 firstx = 0;
3636 }
3637
3638 255164224 i = 0;
3639 255164224 }
3640 1621229568 }
3641 6332928 }
3642
3643
2/2
✓ Branch 0 taken 991876 times.
✓ Branch 1 taken 28272 times.
1020148 if(!firsty)
3644 991876 y += fuzz;
3645 else
3646 {
3647 28272 y += ystep;
3648 28272 ystep = fuzz;
3649 28272 firsty = 0;
3650 }
3651 }
3652 28272 }
3653
3654 18527021 void updatescr(bool allowwavy)
3655 {
3656
4/6
✓ Branch 0 taken 315 times.
✓ Branch 1 taken 18526706 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 315 times.
✓ Branch 4 taken 315 times.
✗ Branch 5 not taken.
18527021 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3657
4/6
✓ Branch 0 taken 315 times.
✓ Branch 1 taken 18526706 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 315 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 315 times.
18527021 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3658 18527021 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3659 18527021 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3660
3661
2/2
✓ Branch 0 taken 18498920 times.
✓ Branch 1 taken 28101 times.
18527021 if(walk_through_walls)
3662 {
3663 28101 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3664 28101 }
3665
3666
1/2
✓ Branch 0 taken 18527021 times.
✗ Branch 1 not taken.
18527021 if(Showpal)
3667 dump_pal(framebuf);
3668
3669
2/2
✓ Branch 0 taken 18010990 times.
✓ Branch 1 taken 516031 times.
18527021 if(!Playing)
3670 516031 black_opening_count=0;
3671
3672
2/2
✓ Branch 0 taken 18358044 times.
✓ Branch 1 taken 168977 times.
18527021 if(black_opening_count<0) //shape is opening up
3673 {
3674 168977 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3675
3676
2/4
✓ Branch 0 taken 168977 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 168977 times.
168977 if(Advance||(!Paused))
3677 {
3678 168977 ++black_opening_count;
3679 168977 }
3680 168977 }
3681
2/2
✓ Branch 0 taken 18309270 times.
✓ Branch 1 taken 48774 times.
18358044 else if(black_opening_count>0) //shape is closing
3682 {
3683 48774 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3684
3685
2/4
✓ Branch 0 taken 48774 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48774 times.
48774 if(Advance||(!Paused))
3686 {
3687 48774 --black_opening_count;
3688 48774 }
3689 48774 }
3690
3691
3/4
✓ Branch 0 taken 18312569 times.
✓ Branch 1 taken 214452 times.
✓ Branch 2 taken 18312569 times.
✗ Branch 3 not taken.
18527021 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3692 {
3693 black_opening_shape = bosCIRCLE;
3694 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3695 refreshTints();
3696 refreshpal=true;
3697 }
3698
3699
2/2
✓ Branch 0 taken 17894031 times.
✓ Branch 1 taken 632990 times.
18527021 if(refreshpal)
3700 {
3701 632990 refreshpal=false;
3702 632990 RAMpal[253] = _RGB(0,0,0);
3703 632990 RAMpal[254] = _RGB(255,255,255);
3704 632990 hw_palette = &RAMpal;
3705 632990 update_hw_pal = true;
3706 632990 refresh_rgb_tables();
3707 632990 }
3708
3709 18527021 bool clearwavy = (wavy <= 0);
3710
3711
2/2
✓ Branch 0 taken 8572 times.
✓ Branch 1 taken 18518449 times.
18527021 if(wavy <= 0)
3712 {
3713 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3714 18518449 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3715 18518449 }
3716
3717 18527021 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3718
3719
6/6
✓ Branch 0 taken 32278 times.
✓ Branch 1 taken 18494743 times.
✓ Branch 2 taken 32156 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 32028 times.
18527021 if(wavy && Playing && allowwavy)
3720 {
3721 32028 draw_wavy(framebuf, wavybuf, wavy,false);
3722 32028 }
3723
3724
2/2
✓ Branch 0 taken 18518449 times.
✓ Branch 1 taken 8572 times.
18527021 if(clearwavy)
3725 18518449 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3726
2/4
✓ Branch 0 taken 8572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8572 times.
8572 else if(Playing && !Paused)
3727 8572 wavy--; // Wavy was set by a script. Decrement it.
3728
3729
3/4
✓ Branch 0 taken 18010990 times.
✓ Branch 1 taken 516031 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18010990 times.
18527021 if(Playing && !Paused)
3730 18010990 ++light_wave_clk;
3731
3732
6/6
✓ Branch 0 taken 18010990 times.
✓ Branch 1 taken 516031 times.
✓ Branch 2 taken 260252 times.
✓ Branch 3 taken 17750738 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 260234 times.
18527021 if(Playing && msg_active && !screenscrolling)
3733 {
3734
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_bg_display_buf->clip))
3735 260167 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3736
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_portrait_display_buf->clip))
3737 260167 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3738
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_txt_display_buf->clip))
3739 260167 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3740 260234 }
3741
3742
3/4
✓ Branch 0 taken 18527021 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18330804 times.
✓ Branch 3 taken 196217 times.
18527021 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3743
3744
2/2
✓ Branch 0 taken 18336077 times.
✓ Branch 1 taken 190944 times.
18527021 if(nosubscr)
3745 {
3746 190944 clear_to_color(panorama, 0);
3747 190944 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3748 190944 }
3749
3750 //TODO: Optimize blit 'overcalls' -Gleeok
3751
2/2
✓ Branch 0 taken 190944 times.
✓ Branch 1 taken 18336077 times.
18527021 BITMAP *source = nosubscr ? panorama : wavybuf;
3752 18527021 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3753
3754 18527021 update_hw_screen();
3755 18527021 }
3756
3757 //----------------------------------------------------------------
3758
3759 static PALETTE syspal;
3760 int32_t onGUISnapshot()
3761 {
3762 char buf[200];
3763 int32_t num=0;
3764 do
3765 {
3766 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3767 }
3768 while(num<99999 && exists(buf));
3769
3770 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3771 InfoDialog("Error", "Failed to save snapshot").show();
3772
3773 return D_O_K;
3774 }
3775
3776 int32_t onNonGUISnapshot()
3777 {
3778 PALETTE temppal;
3779 get_palette(temppal);
3780 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3781
3782 char buf[200];
3783 int32_t num=0;
3784
3785 do
3786 {
3787 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3788 }
3789 while(num<99999 && exists(buf));
3790
3791 if (hero_scr && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3792 {
3793 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3794 clear_to_color(b,0);
3795 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3796 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3797 destroy_bitmap(b);
3798 }
3799 else
3800 {
3801 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3802 }
3803
3804 return D_O_K;
3805 }
3806
3807 int32_t onSnapshot()
3808 {
3809 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3810 {
3811 onGUISnapshot();
3812 }
3813 else
3814 {
3815 onNonGUISnapshot();
3816 }
3817
3818 return D_O_K;
3819 }
3820
3821 int32_t onSaveMapPic()
3822 {
3823 char buf[200];
3824 int32_t num=0;
3825 BITMAP* _screen_draw_buffer = NULL;
3826 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3827
3828 do
3829 {
3830 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3831 }
3832 while(num<99999 && exists(buf));
3833
3834 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3835 clear_to_color(mappic, BLACK);
3836
3837 if(!mappic)
3838 {
3839 enter_sys_pal();
3840 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3841 exit_sys_pal();
3842 return D_O_K;;
3843 }
3844
3845 clear_to_color(_screen_draw_buffer, BLACK);
3846
3847 auto prev_viewport = viewport;
3848 viewport.x = 0;
3849 viewport.y = 0;
3850
3851 // draw the map
3852
3853 bool classic_draw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3854 for(int32_t y=0; y<8; y++)
3855 {
3856 for(int32_t x=0; x<16; x++)
3857 {
3858 if (!displayOnMap(x, y))
3859 continue;
3860
3861 int screen = map_scr_xy_to_index(x, y);
3862 auto scrs = loadscr2(screen);
3863 mapscr* scr = &scrs[0];
3864 if (!scr->is_valid())
3865 continue;
3866
3867 screen_handles_t screen_handles;
3868 for (int i = 0; i <= 6; i++)
3869 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3870
3871 int xx = 0;
3872 int yy = -playing_field_offset;
3873
3874 if (!classic_draw)
3875 for (int layer = -7; layer <= -4; ++layer)
3876 do_ffc_layer(_screen_draw_buffer, layer, screen_handles[0], xx, yy);
3877
3878 if(classic_draw)
3879 {
3880 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3881 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3882 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3883 }
3884
3885 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3886 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3887 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3888
3889 if(!classic_draw)
3890 {
3891 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3892 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3893 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3894 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3895 }
3896
3897 if(lenscheck(scr,0))
3898 putscr(scr, _screen_draw_buffer, 0, 0);
3899 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3900 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3901 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3902
3903 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3904 {
3905 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3906 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3907 }
3908
3909 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3910 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3911 {
3912 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3913 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3914 {
3915 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3916 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3917 }
3918 }
3919
3920 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3921 {
3922 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3923 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3924 }
3925
3926 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3927 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3928 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3929 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3930 {
3931 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3932 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3933 }
3934 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3935 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3936 if(replay_version_check(40))
3937 do_ffc_layer(_screen_draw_buffer, -1000, screen_handles[0], xx, yy);
3938 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3939 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3940 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3941
3942 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3943 }
3944 }
3945
3946 viewport = prev_viewport;
3947 save_bitmap(buf,mappic,RAMpal);
3948 destroy_bitmap(mappic);
3949 destroy_bitmap(_screen_draw_buffer);
3950 return D_O_K;
3951 }
3952
3953 47 void f_Quit(int32_t type)
3954 {
3955
2/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
47 if(type==qQUIT && !Playing)
3956 return;
3957
3958 47 bool from_menu = is_sys_pal;
3959
3960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if(!from_menu)
3961 {
3962 47 music_pause();
3963 47 pause_all_sfx();
3964 47 sys_mouse();
3965 47 }
3966 47 enter_sys_pal();
3967 47 clear_keybuf();
3968
3969
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 13 times.
47 if (replay_version_check(0, 10))
3970 13 replay_poll();
3971
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if (replay_is_replaying())
3972 47 replay_peek_quit();
3973
3974
1/2
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
47 if (!replay_is_replaying())
3975 switch(type)
3976 {
3977 case qQUIT:
3978 onQuit();
3979 break;
3980
3981 case qRESET:
3982 onReset();
3983 break;
3984
3985 case qEXIT:
3986 onExit();
3987 break;
3988 }
3989
3990
1/2
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
47 if(Quit)
3991 {
3992 47 kill_sfx();
3993 47 music_stop();
3994 47 exit_sys_pal();
3995 47 update_hw_screen();
3996 47 }
3997 else
3998 {
3999 exit_sys_pal();
4000 if(!from_menu)
4001 {
4002 music_resume();
4003 resume_all_sfx();
4004 }
4005 }
4006
4007
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if(!from_menu)
4008 47 game_mouse();
4009 47 eat_buttons();
4010
4011 47 zc_readrawkey(KEY_ESC);
4012
4013 47 zc_readrawkey(KEY_ENTER);
4014 47 }
4015
4016 //----------------------------------------------------------------
4017
4018 int32_t onNoWalls()
4019 {
4020 cheats_enqueue(Cheat::Walls);
4021 return D_O_K;
4022 }
4023
4024 int32_t onIgnoreSideview()
4025 {
4026 cheats_enqueue(Cheat::IgnoreSideView);
4027 return D_O_K;
4028 }
4029
4030 18525634 int32_t input_idle(bool checkmouse)
4031 {
4032 static int32_t mx, my, mz, mb;
4033
4034
4/6
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4963549 times.
✓ Branch 3 taken 13562085 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4963549 times.
23489183 if(keypressed() || zc_key_pressed() ||
4035
4/8
✓ Branch 0 taken 4963549 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4963549 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4963549 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4963549 times.
✗ Branch 7 not taken.
4963549 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4036 {
4037 13562085 idle_count = 0;
4038
4039
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13562085 times.
13562085 if(active_count < MAX_ACTIVE)
4040 {
4041 13562085 ++active_count;
4042 13562085 }
4043 13562085 }
4044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4963549 times.
4963549 else if(idle_count < MAX_IDLE)
4045 {
4046 4963549 ++idle_count;
4047 4963549 active_count = 0;
4048 4963549 }
4049
4050 18525634 mx = mouse_x;
4051 18525634 my = mouse_y;
4052 18525634 mz = mouse_z;
4053 18525634 mb = mouse_b;
4054
4055 18525634 return idle_count;
4056 }
4057
4058 int32_t onGoFast()
4059 {
4060 cheats_enqueue(Cheat::Fast);
4061 return D_O_K;
4062 }
4063
4064 int32_t onKillCheat()
4065 {
4066 cheats_enqueue(Cheat::Kill);
4067 return D_O_K;
4068 }
4069
4070 int32_t onSecretsCheat()
4071 {
4072 cheats_enqueue(Cheat::TrigSecrets);
4073 return D_O_K;
4074 }
4075 int32_t onSecretsCheatPerm()
4076 {
4077 cheats_enqueue(Cheat::TrigSecretsPerm);
4078 return D_O_K;
4079 }
4080
4081 int32_t onShowLayer0()
4082 {
4083 show_layers[0] = !show_layers[0];
4084 return D_O_K;
4085 }
4086 int32_t onShowLayer1()
4087 {
4088 show_layers[1] = !show_layers[1];
4089 return D_O_K;
4090 }
4091 int32_t onShowLayer2()
4092 {
4093 show_layers[2] = !show_layers[2];
4094 return D_O_K;
4095 }
4096 int32_t onShowLayer3()
4097 {
4098 show_layers[3] = !show_layers[3];
4099 return D_O_K;
4100 }
4101 int32_t onShowLayer4()
4102 {
4103 show_layers[4] = !show_layers[4];
4104 return D_O_K;
4105 }
4106 int32_t onShowLayer5()
4107 {
4108 show_layers[5] = !show_layers[5];
4109 return D_O_K;
4110 }
4111 int32_t onShowLayer6()
4112 {
4113 show_layers[6] = !show_layers[6];
4114 return D_O_K;
4115 }
4116 int32_t onShowLayerO()
4117 {
4118 show_layer_over=!show_layer_over;
4119 return D_O_K;
4120 }
4121 int32_t onShowLayerP()
4122 {
4123 show_layer_push=!show_layer_push;
4124 return D_O_K;
4125 }
4126 int32_t onShowLayerS()
4127 {
4128 show_sprites=!show_sprites;
4129 return D_O_K;
4130 }
4131 int32_t onShowLayerF()
4132 {
4133 show_ffcs=!show_ffcs;
4134 return D_O_K;
4135 }
4136 int32_t onShowLayerW()
4137 {
4138 show_walkflags=!show_walkflags;
4139 if(show_walkflags)
4140 show_effectflags = false;
4141 return D_O_K;
4142 }
4143 int32_t onShowLayerE()
4144 {
4145 show_effectflags=!show_effectflags;
4146 if(show_effectflags)
4147 show_walkflags = false;
4148 return D_O_K;
4149 }
4150 int32_t onShowFFScripts()
4151 {
4152 show_ff_scripts=!show_ff_scripts;
4153 return D_O_K;
4154 }
4155 int32_t onShowHitboxes()
4156 {
4157 show_hitboxes=!show_hitboxes;
4158 return D_O_K;
4159 }
4160 int32_t onShowInfoOpacity()
4161 {
4162 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4163 zc_set_config("zc","debug_info_opacity",info_opacity);
4164 return D_O_K;
4165 }
4166
4167 int32_t onLightSwitch()
4168 {
4169 cheats_enqueue(Cheat::Light);
4170 return D_O_K;
4171 }
4172
4173 int32_t onGoTo();
4174 int32_t onGoToComplete();
4175
4176 18525634 bool handle_close_btn_quit()
4177 {
4178
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(close_button_quit)
4179 {
4180 close_button_quit=false;
4181 f_Quit(qEXIT);
4182 }
4183 18525634 return (exiting_program = Quit==qEXIT);
4184 }
4185
4186 18525634 void syskeys()
4187 {
4188 18525634 update_system_keys();
4189
4190 int32_t oldtitle_version;
4191
4192 18525634 poll_joystick();
4193
4194 18525634 handle_close_btn_quit();
4195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
18525634 if(Quit == qEXIT) return;
4196
4197
2/10
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18525634 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18525634 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4198 {
4199 System();
4200 }
4201
4202 18525634 mouse_down=gui_mouse_b();
4203
4204
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(zc_read_system_key(KEY_F1))
4205 {
4206 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4207 {
4208 halt=!halt;
4209 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4210 }
4211 else
4212 {
4213 Throttlefps=!Throttlefps;
4214 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4215 }
4216 }
4217
4218
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(zc_read_system_key(KEY_F2))
4219 {
4220 ShowFPS=!ShowFPS;
4221 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4222 }
4223
4224
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18525634 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4225
4226
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18525634 if(zc_read_system_key(KEY_F4) && Playing)
4227 {
4228 Paused=true;
4229 Advance=true;
4230 }
4231
4232
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(zc_read_system_key(KEY_F6)) onTryQuit();
4233
4234 #ifndef ALLEGRO_MACOSX
4235
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4236
4237
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4238 #else
4239 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4240
4241 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4242 #endif
4243
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18525634 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4244
4245
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if (zc_read_system_key(KEY_F12))
4246 {
4247 onSnapshot();
4248 }
4249
4250
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18525634 if(debug_enabled && zc_read_system_key(KEY_TAB))
4251 set_debug(!get_debug());
4252
4253
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(CheatModifierKeys())
4254 {
4255 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4256 {
4257 if(!bindable_cheat(c))
4258 continue;
4259 if(get_debug() || cheat >= cheat_lvl(c))
4260 {
4261 if(checkcheat(c))
4262 cheats_hit_bind(c);
4263 }
4264 }
4265 }
4266
4267
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(volkeys)
4268 {
4269 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4270
4271 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4272
4273 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4274
4275 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4276 }
4277
4278
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18525634 if(!get_debug() || !SystemKeys || replay_is_replaying())
4279 18525634 goto bottom;
4280
4281 if(zc_readkey(KEY_P)) Paused=!Paused;
4282
4283 if(zc_readkey(KEY_A))
4284 {
4285 Paused=true;
4286 Advance=true;
4287 }
4288
4289 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4290 #ifndef ALLEGRO_MACOSX
4291 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4292
4293 if(zc_readkey(KEY_F7))
4294 {
4295 Matrix(ss_speed, ss_density, 0);
4296 game_pal();
4297 }
4298 #else
4299 // The reason these are different on Mac in the first place is that
4300 // the OS doesn't let us use F9 and F10...
4301 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4302
4303 if(zc_readkey(KEY_F9))
4304 {
4305 Matrix(ss_speed, ss_density, 0);
4306 game_pal();
4307 }
4308 #endif
4309 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4310 {
4311 //change containers
4312 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4313 {
4314 //magic containers
4315 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4316 {
4317 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4318 }
4319 else
4320 {
4321 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4322 }
4323 }
4324 else
4325 {
4326 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4327 {
4328 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4329 }
4330 else
4331 {
4332 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4333 }
4334 }
4335 }
4336
4337 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4338 {
4339 //change containers
4340 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4341 {
4342 //magic containers
4343 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4344 {
4345 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4346 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4347 //heart containers
4348 }
4349 else
4350 {
4351 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4352 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4353 }
4354 }
4355 else
4356 {
4357 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4358 {
4359 game->set_magic(zc_max(game->get_magic()-1,0));
4360 }
4361 else
4362 {
4363 game->set_life(zc_max(game->get_life()-1,0));
4364 }
4365 }
4366 }
4367
4368 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4369
4370 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4371
4372 verifyBothWeapons();
4373
4374 bottom:
4375
4376
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(input_idle(true) > after_time())
4377 {
4378 Matrix(ss_speed, ss_density, 0);
4379 game_pal();
4380 }
4381 18525634 }
4382
4383 1308802 void checkQuitKeys()
4384 {
4385 #ifndef ALLEGRO_MACOSX
4386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1308802 times.
1308802 if(key[KEY_F9]) f_Quit(qRESET);
4387
4388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1308802 times.
1308802 if(key[KEY_F10]) f_Quit(qEXIT);
4389 #else
4390 if(key[KEY_F7]) f_Quit(qRESET);
4391
4392 if(key[KEY_F8]) f_Quit(qEXIT);
4393 #endif
4394 1308802 }
4395
4396 18525834 bool CheatModifierKeys()
4397 {
4398 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4399 // to trigger cheats.
4400
2/2
✓ Branch 0 taken 18525534 times.
✓ Branch 1 taken 300 times.
18525834 if (replay_is_replaying())
4401 18525534 return false;
4402
4403
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4404
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4406 {
4407
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4408 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4409 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4410 {
4411 return true;
4412 }
4413 }
4414 100 return false;
4415 18525634 }
4416
4417 //99:05:54, for some reason?
4418 #define OLDMAXTIME 21405240
4419 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4420 #define MAXTIME 1944000000
4421
4422 // (qr, value)
4423 418 static std::queue<std::pair<int, bool>> change_qr_queue;
4424
4425 7 void enqueue_qr_change(int qr, bool value)
4426 {
4427 7 change_qr_queue.push({qr, value});
4428 7 }
4429
4430 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4431 // and soon executed here.
4432 // During playing back a replay file, the replay system adds to the same queue and
4433 // is executed here too.
4434 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4435 // could be later extended to all QRs (perhaps as a cheat).
4436 18526058 void process_enqueued_qr_changes()
4437 {
4438
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 18525957 times.
18526058 if (replay_is_replaying())
4439 18525957 replay_do_qrs();
4440
4441
2/2
✓ Branch 0 taken 18526058 times.
✓ Branch 1 taken 7 times.
18526065 while (!change_qr_queue.empty())
4442 {
4443 28 auto [qr, value] = change_qr_queue.front();
4444 7 change_qr_queue.pop();
4445
4446 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4447 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4448 14 _qrs_unpacked[qr] = value;
4449 7 apply_qr_rule(qr);
4450
4451
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4452 2 replay_step_qr(qr, value);
4453 }
4454 18526058 }
4455
4456 18527021 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4457 {
4458
1/2
✓ Branch 0 taken 18527021 times.
✗ Branch 1 not taken.
18527021 if(zcmusic!=NULL)
4459 {
4460 zcmusic_poll();
4461 }
4462 18527021 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4463
4464 18527021 updatescr(allowwavy);
4465
4466 18527021 Advance=false;
4467
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18527021 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18527021 times.
18527021 while(Paused && !Advance && !Quit)
4468 {
4469 // have to call this, otherwise we'll get an infinite loop
4470 syskeys();
4471 if(allowF6Script)
4472 {
4473 FFCore.runF6Engine();
4474 }
4475
4476 #ifdef _WIN32
4477
4478 if(use_dwm_flush)
4479 {
4480 do_DwmFlush();
4481 }
4482
4483 #endif
4484
4485 // to keep music playing
4486 if(zcmusic!=NULL)
4487 {
4488 zcmusic_poll();
4489 }
4490
4491 update_hw_screen();
4492 }
4493
4494
2/2
✓ Branch 0 taken 18525663 times.
✓ Branch 1 taken 1358 times.
18527021 if(Quit)
4495 1358 return;
4496
4497
3/4
✓ Branch 0 taken 18009944 times.
✓ Branch 1 taken 515719 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18009944 times.
18525663 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4498 18009944 game->change_time(1);
4499
4500 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4501
4502 18525663 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4503
2/2
✓ Branch 0 taken 8726051 times.
✓ Branch 1 taken 9799612 times.
18525663 if (replay_version_check(0, 16))
4504 9799612 should_reset_down_state = replay_version_check(11, 16);
4505
2/2
✓ Branch 0 taken 15096705 times.
✓ Branch 1 taken 3428958 times.
18525663 if (should_reset_down_state)
4506 {
4507
2/2
✓ Branch 0 taken 61721244 times.
✓ Branch 1 taken 3428958 times.
65150202 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4508 61721244 down_control_states[i] = raw_control_state[i];
4509 3428958 }
4510
4511
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 18525634 times.
18525663 if (replay_is_active())
4512 {
4513
2/2
✓ Branch 0 taken 1545428 times.
✓ Branch 1 taken 16980206 times.
18525634 if (replay_version_check(3))
4514 16980206 replay_poll();
4515
4516
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 11046723 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
18525634 if (replay_version_check(11) || replay_version_check(6, 8))
4517 11147258 replay_peek_input();
4518 18525634 }
4519
4520 18525663 process_enqueued_qr_changes();
4521
4522 18525663 load_control_called_this_frame = false;
4523
4524 18525663 poll_keyboard();
4525 18525663 update_keys();
4526
4527 18525663 ++frame;
4528
4529
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 18525534 times.
18525663 if (replay_is_replaying())
4530 18525534 replay_do_cheats();
4531 18525663 syskeys();
4532
4533 // The mouse variables can change from the mouse thread at anytime during a frame,
4534 // so save the result at the start so that replaying is consistent.
4535 18525663 script_mouse_x = gui_mouse_x();
4536 18525663 script_mouse_y = gui_mouse_y();
4537 18525663 script_mouse_z = mouse_z;
4538 18525663 script_mouse_b = mouse_b;
4539
4540 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4541 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4542 // approach here means it doesn't matter which call adds the cheat.
4543 18525663 cheats_execute_queued();
4544
4545
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 18525534 times.
18525663 if (replay_is_replaying())
4546 18525534 replay_peek_quit();
4547
2/2
✓ Branch 0 taken 18525616 times.
✓ Branch 1 taken 47 times.
18525663 if (GameFlags & GAMEFLAG_TRYQUIT)
4548 47 replay_step_quit(0);
4549
2/2
✓ Branch 0 taken 3314 times.
✓ Branch 1 taken 18522349 times.
18525663 if(allowF6Script)
4550 18522349 FFCore.runF6Engine();
4551
2/2
✓ Branch 0 taken 757 times.
✓ Branch 1 taken 18524906 times.
18525663 if (Quit)
4552 757 replay_step_quit(Quit);
4553
4554 #ifdef _WIN32
4555
4556 if(use_dwm_flush)
4557 {
4558 do_DwmFlush();
4559 }
4560
4561 #endif
4562
4563
2/2
✓ Branch 0 taken 208637 times.
✓ Branch 1 taken 18317026 times.
18525663 if(sfxcleanup)
4564 18317026 sfx_cleanup();
4565
4566 18525663 frame_timings_poll();
4567
4568 #ifdef __EMSCRIPTEN__
4569 // Yield the main thread back to the browser occasionally.
4570 if (is_headless())
4571 {
4572 static int rate = 10000;
4573 static int force_yield = rate;
4574 if (force_yield++ >= rate)
4575 {
4576 force_yield = 0;
4577 emscripten_sleep(0);
4578 }
4579 }
4580 #endif
4581
4582
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18525563 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18525663 if (zqtesting_mode && test_mode_auto_restart)
4583 {
4584 static auto last_write_time = fs::last_write_time(qstpath);
4585 static auto last_check = std::chrono::system_clock::now();
4586
4587 if (std::chrono::system_clock::now() - last_check > 200ms)
4588 {
4589 last_check = std::chrono::system_clock::now();
4590 auto write_time = fs::last_write_time(qstpath);
4591 if (last_write_time != write_time)
4592 {
4593 last_write_time = write_time;
4594 disableClickToFreeze = false;
4595 Quit = qRESET;
4596 replay_quit();
4597 }
4598 }
4599 }
4600 18527021 }
4601
4602 590 void zapout()
4603 {
4604 590 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4605 590 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4606
4607 590 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4608 590 script_drawing_commands.Clear();
4609
4610 // zap out
4611
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 14160 times.
14750 for(int32_t i=1; i<=24; i++)
4612 {
4613 14160 draw_fuzzy(i);
4614 14160 advanceframe(true);
4615
4616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160 times.
14160 if(Quit)
4617 {
4618 break;
4619 }
4620 14160 }
4621 590 }
4622
4623 588 void zapin()
4624 {
4625 588 FFCore.warpScriptCheck();
4626 588 draw_screen();
4627 588 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4628 588 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4629
4630 // zap out
4631 588 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4632
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 14112 times.
14700 for(int32_t i=24; i>=1; i--)
4633 {
4634 14112 draw_fuzzy(i);
4635 14112 advanceframe(true);
4636
4637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14112 times.
14112 if(Quit)
4638 {
4639 break;
4640 }
4641 14112 }
4642 588 }
4643
4644
4645 235 void wavyout(bool showhero)
4646 {
4647 235 draw_screen(showhero);
4648
4649 235 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4650 235 clear_to_color(wavebuf,0);
4651 235 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4652
4653 static PALETTE wavepal;
4654
4655 int32_t ofs;
4656 235 int32_t amplitude=8;
4657
4658 235 int32_t wavelength=4;
4659 235 int height = viewport.visible_height(show_bottom_8px);
4660 235 double palpos=0, palstep=4, palstop=126;
4661
4662 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4663
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<height; i+=wavelength)
4664 {
4665
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4666 {
4667 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4668 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4669 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4670 2520320 }
4671
4672 9845 palpos+=palstep;
4673
4674
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4675 {
4676 9845 hw_palette = &wavepal;
4677 9845 update_hw_pal = true;
4678 9845 }
4679 else
4680 {
4681 hw_palette = &RAMpal;
4682 update_hw_pal = true;
4683 }
4684
4685
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4686 {
4687
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4688 {
4689 423413760 ofs=0;
4690
4691
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4692 {
4693 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4694 103224320 }
4695
4696 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4697 423413760 }
4698 1653960 }
4699
4700 9845 advanceframe(true);
4701
4702
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4703 1 break;
4704 9844 }
4705
4706 235 destroy_bitmap(wavebuf);
4707
4708 235 hw_palette = &RAMpal;
4709 235 update_hw_pal = true;
4710 235 }
4711
4712 232 void wavyin()
4713 {
4714 232 draw_screen();
4715
4716 232 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4717 232 clear_to_color(wavebuf,0);
4718 232 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4719
4720 static PALETTE wavepal;
4721
4722 232 refreshpal=false;
4723 int32_t ofs;
4724 232 int32_t amplitude=8;
4725 232 int32_t wavelength=4;
4726 232 int height = viewport.visible_height(show_bottom_8px);
4727 232 double palpos=height, palstep=4, palstop=126;
4728
4729 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4730
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<height; i+=wavelength)
4731 {
4732
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4733 {
4734 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4735 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4736 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4737 2483968 }
4738
4739 9703 palpos-=palstep;
4740
4741
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4742 {
4743 9703 hw_palette = &wavepal;
4744 9703 update_hw_pal = true;
4745 9703 }
4746 else
4747 {
4748 hw_palette = &RAMpal;
4749 update_hw_pal = true;
4750 }
4751
4752
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4753 {
4754
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4755 {
4756 417306624 ofs=0;
4757
4758
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(height-1-i))&&(j&1))
4759 {
4760 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4761 104337152 }
4762
4763 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4764 417306624 }
4765 1630104 }
4766
4767 9703 advanceframe(true);
4768
4769
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4770 1 break;
4771 9702 }
4772
4773 232 destroy_bitmap(wavebuf);
4774
4775 232 hw_palette = &RAMpal;
4776 232 update_hw_pal = true;
4777 232 }
4778
4779 4346 void blackscr(int32_t fcnt,bool showsubscr)
4780 {
4781 4346 reset_pal_cycling();
4782 4346 script_drawing_commands.Clear();
4783
4784 4346 FFCore.warpScriptCheck();
4785 4346 bool showtime = game->should_show_time();
4786
2/2
✓ Branch 0 taken 4339 times.
✓ Branch 1 taken 129937 times.
134276 while(fcnt>0)
4787 {
4788 129937 clear_bitmap(framebuf);
4789
4790
2/2
✓ Branch 0 taken 59310 times.
✓ Branch 1 taken 70627 times.
129937 if(showsubscr)
4791 {
4792 70627 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4793
3/4
✓ Branch 0 taken 70627 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1410 times.
✓ Branch 3 taken 69217 times.
70627 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4794 {
4795 1410 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4796 1410 }
4797 70627 }
4798
4799 129937 advanceframe(true);
4800
4801
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129930 times.
129937 if(Quit)
4802 7 break;
4803
4804 129930 --fcnt;
4805 }
4806 4346 }
4807
4808 2740 void openscreen(int32_t shape)
4809 {
4810 2740 update_viewport();
4811 2740 is_opening_screen = true;
4812 2740 reset_pal_cycling();
4813 2740 black_opening_count=0;
4814
4815
3/4
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 2209 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 531 times.
2740 if(COOLSCROLL || shape>-1)
4816 {
4817 2209 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4818 2209 return;
4819 }
4820 else
4821 {
4822 531 Hero.setDontDraw(true);
4823 531 show_subscreen_dmap_dots=false;
4824 531 show_subscreen_numbers=false;
4825 531 show_subscreen_life=false;
4826 }
4827
4828 531 int32_t x=128;
4829
4830 531 FFCore.warpScriptCheck();
4831
2/2
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 42480 times.
43011 for(int32_t i=0; i<80; i++)
4832 {
4833 42480 draw_screen();
4834 42480 x=128-(((i*128/80)/8)*8);
4835
4836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(x>0)
4837 {
4838 42480 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4839 42480 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4840 42480 }
4841
4842 42480 advanceframe(true);
4843
4844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(Quit)
4845 {
4846 break;
4847 }
4848 42480 }
4849
4850 531 Hero.setDontDraw(false);
4851 531 show_subscreen_items=true;
4852 531 show_subscreen_dmap_dots=true;
4853 531 show_subscreen_numbers=true;
4854 531 show_subscreen_life=true;
4855 2740 }
4856
4857 14 void closescreen(int32_t shape)
4858 {
4859 14 is_opening_screen = false;
4860 14 reset_pal_cycling();
4861 14 black_opening_count=0;
4862
4863
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(COOLSCROLL || shape>-1)
4864 {
4865 14 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4866 14 return;
4867 }
4868 else
4869 {
4870 Hero.setDontDraw(true);
4871 show_subscreen_dmap_dots=false;
4872 show_subscreen_numbers=false;
4873 // show_subscreen_items=false;
4874 show_subscreen_life=false;
4875 }
4876
4877 int32_t x=128;
4878
4879 FFCore.warpScriptCheck();
4880 for(int32_t i=79; i>=0; --i)
4881 {
4882 draw_screen();
4883 x=128-(((i*128/80)/8)*8);
4884
4885 if(x>0)
4886 {
4887 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4888 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4889 }
4890
4891 advanceframe(true);
4892
4893 if(Quit)
4894 {
4895 break;
4896 }
4897 }
4898
4899 Hero.setDontDraw(false);
4900 show_subscreen_items=true;
4901 show_subscreen_dmap_dots=true;
4902 14 }
4903
4904 324 int32_t TriforceCount()
4905 {
4906 324 int32_t c=0;
4907
4908
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 324 times.
2916 for(int32_t i=1; i<=8; i++)
4909
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 2108 times.
4700 if(game->lvlitems[i]&(1 << li_mcguffin))
4910 2108 ++c;
4911
4912 324 return c;
4913 }
4914
4915 int32_t onCustomGame()
4916 {
4917 auto save = get_unset_save_slot();
4918 if (!save)
4919 return D_CLOSE;
4920
4921 if (prompt_for_quest_path(save->header->qstpath))
4922 {
4923 save->header->qstpath = qstpath;
4924 return D_O_K;
4925 }
4926
4927 return D_CLOSE;
4928 }
4929
4930 int32_t onContinue()
4931 {
4932 return D_CLOSE;
4933 }
4934
4935 int32_t onThrottleFPS()
4936 {
4937 Throttlefps = !Throttlefps;
4938 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4939 return D_O_K;
4940 }
4941
4942 int32_t onWinPosSave()
4943 {
4944 SaveWinPos = !SaveWinPos;
4945 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4946 return D_O_K;
4947 }
4948 int32_t onIntegerScaling()
4949 {
4950 scaleForceInteger = !scaleForceInteger;
4951 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4952 return D_O_K;
4953 }
4954 int32_t onStretchGame()
4955 {
4956 stretchGame = !stretchGame;
4957 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4958 return D_O_K;
4959 }
4960
4961 int32_t onClickToFreeze()
4962 {
4963 ClickToFreeze = !ClickToFreeze;
4964 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4965 return D_O_K;
4966 }
4967
4968 int32_t OnSaveZCConfig()
4969 {
4970 if(jwin_alert3(
4971 "Save Configuration",
4972 "Are you sure that you wish to save your present configuration settings?",
4973 "This will overwrite your prior settings!",
4974 NULL,
4975 "&Yes",
4976 "&No",
4977 NULL,
4978 'y',
4979 'n',
4980 0,
4981 get_zc_font(font_lfont)) == 1)
4982 {
4983 save_game_configs();
4984 return D_O_K;
4985 }
4986 else return D_O_K;
4987 }
4988
4989 int32_t OnnClearQuestDir()
4990 {
4991 auto current_path = fs::current_path() / "quests";
4992 if(jwin_alert3(
4993 "Clear Current Directory Cache",
4994 "Are you sure that you wish to reset where ZC Player looks for quests?",
4995 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4996 NULL,
4997 "&Yes",
4998 "&No",
4999 NULL,
5000 'y',
5001 'n',
5002 0,
5003 get_zc_font(font_lfont)) == 1)
5004 {
5005 zc_set_config("zeldadx","quest_dir","quests");
5006 flush_config_file();
5007 strcpy(qstdir,"quests");
5008 #ifdef __EMSCRIPTEN__
5009 em_sync_fs();
5010 #endif
5011 return D_O_K;
5012 }
5013 else return D_O_K;
5014 }
5015
5016 int32_t onConsole()
5017 {
5018 if ( !console_enabled )
5019 {
5020 AlertDialog("ZC Console",
5021 "Open the ZC Console?"
5022 "\nThis will display any messages logged by scripts,"
5023 " including errors.",
5024 [&](bool ret,bool)
5025 {
5026 if(ret)
5027 {
5028 FFCore.ZScriptConsole(true);
5029 }
5030 }).show();
5031 return D_O_K;
5032 }
5033 else
5034 {
5035 FFCore.ZScriptConsole(false);
5036 return D_O_K;
5037 }
5038 }
5039
5040 int32_t onClrConsoleOnReload()
5041 {
5042 clearConsoleOnReload = !clearConsoleOnReload;
5043 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5044 return D_O_K;
5045 }
5046 int32_t onClrConsoleOnLoad()
5047 {
5048 clearConsoleOnLoad = !clearConsoleOnLoad;
5049 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5050 return D_O_K;
5051 }
5052
5053
5054 int32_t onFrameSkip()
5055 {
5056 FrameSkip = !FrameSkip;
5057 return D_O_K;
5058 }
5059
5060 int32_t onSaveDragResize()
5061 {
5062 SaveDragResize = !SaveDragResize;
5063 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5064 return D_O_K;
5065 }
5066
5067 int32_t onDragAspect()
5068 {
5069 DragAspect = !DragAspect;
5070 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5071 return D_O_K;
5072 }
5073
5074 int32_t onTransLayers()
5075 {
5076 TransLayers = !TransLayers;
5077 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5078 return D_O_K;
5079 }
5080
5081 int32_t onNESquit()
5082 {
5083 NESquit = !NESquit;
5084 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5085 return D_O_K;
5086 }
5087
5088 int32_t onVolKeys()
5089 {
5090 volkeys = !volkeys;
5091 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5092 return D_O_K;
5093 }
5094
5095 int32_t onShowFPS()
5096 {
5097 ShowFPS = !ShowFPS;
5098 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5099 return D_O_K;
5100 }
5101
5102 int32_t onShowTime()
5103 {
5104 ShowGameTime = !ShowGameTime;
5105 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5106 return D_O_K;
5107 }
5108
5109 2186024812 bool is_Fkey(int32_t k)
5110 {
5111
2/2
✓ Branch 0 taken 222307608 times.
✓ Branch 1 taken 1963717204 times.
2186024812 switch(k)
5112 {
5113 case KEY_F1:
5114 case KEY_F2:
5115 case KEY_F3:
5116 case KEY_F4:
5117 case KEY_F5:
5118 case KEY_F6:
5119 case KEY_F7:
5120 case KEY_F8:
5121 case KEY_F9:
5122 case KEY_F10:
5123 case KEY_F11:
5124 case KEY_F12:
5125 222307608 return true;
5126 }
5127
5128 1963717204 return false;
5129 2186024812 }
5130
5131 void kb_getkey(DIALOG *d);
5132
5133 //Used by all keyboard key settings dialogues.
5134 void kb_clearjoystick(DIALOG *d)
5135 {
5136 d->flags|=D_SELECTED;
5137
5138 jwin_button_proc(MSG_DRAW,d,0);
5139 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5140 // text_mode(vc(11));
5141 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5142 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5143
5144 update_hw_screen();
5145
5146 clear_keybuf();
5147 int32_t k = next_press_key();
5148 clear_keybuf();
5149
5150 //shnarf
5151 //47=f1
5152 //59=esc
5153 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5154 // *((int32_t*)d->dp3) = k;
5155 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5156
5157
5158 d->flags&=~D_SELECTED;
5159 }
5160
5161 //Clears key to 0.
5162 //Used by all keyboard key settings dialogues.
5163 void kb_clearkey(DIALOG *d);
5164
5165 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5166 {
5167 switch(msg)
5168 {
5169 case MSG_KEY:
5170 case MSG_CLICK:
5171
5172 kb_clearjoystick(d);
5173
5174 while(gui_mouse_b())
5175 {
5176 clear_keybuf();
5177 rest(1);
5178 }
5179
5180 return D_REDRAW;
5181 }
5182
5183 return jwin_button_proc(msg,d,c);
5184 }
5185
5186 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5187 //Only used in keyboard settings dialogues to clear keys.
5188 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5189
5190 int32_t j_getbtn(DIALOG *d)
5191 {
5192 d->flags|=D_SELECTED;
5193 jwin_button_proc(MSG_DRAW,d,0);
5194 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5195 // text_mode(vc(11));
5196 int32_t y = screen->h/2 - 12;
5197 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5198 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5199 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5200
5201 update_hw_screen();
5202
5203 int32_t b = next_joy_input(true);
5204 if (b == -2)
5205 return D_CLOSE;
5206
5207 if(b>=0)
5208 *((int32_t*)d->dp3) = b;
5209
5210 d->flags&=~D_SELECTED;
5211
5212 return D_O_K;
5213 }
5214
5215 void j_getstick(DIALOG *d)
5216 {
5217 d->flags|=D_SELECTED;
5218 jwin_button_proc(MSG_DRAW,d,0);
5219 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5220 // text_mode(vc(11));
5221 int32_t y = screen->h/2 - 12;
5222 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5223 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5224 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5225
5226 update_hw_screen();
5227
5228 int32_t b = next_joy_input(false);
5229
5230 if(b>=0)
5231 *((int32_t*)d->dp3) = b;
5232
5233 d->flags&=~D_SELECTED;
5234 }
5235
5236 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5237 {
5238 switch(msg)
5239 {
5240 case MSG_KEY:
5241 case MSG_CLICK:
5242
5243 int ret = j_getbtn(d);
5244 if (ret != D_O_K)
5245 return ret;
5246
5247 while(gui_mouse_b()) {
5248 rest(1);
5249 clear_keybuf();
5250 }
5251
5252 return D_REDRAW;
5253 }
5254
5255 return jwin_button_proc(msg,d,c);
5256 }
5257
5258 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5259 {
5260 switch(msg)
5261 {
5262 case MSG_KEY:
5263 case MSG_CLICK:
5264
5265 j_getstick(d);
5266
5267 while(gui_mouse_b()) {
5268 rest(1);
5269 clear_keybuf();
5270 }
5271
5272 return D_REDRAW;
5273 }
5274
5275 return jwin_button_proc(msg,d,c);
5276 }
5277
5278 //shnarf
5279 extern const char *key_str[];
5280 std::string get_keystr(int key);
5281
5282 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5283
5284 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5285 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5286 str_primary_stick[80], str_secondary_stick[80];
5287
5288 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5289 {
5290 //these are here to bypass compiler warnings about unused arguments
5291 c=c;
5292
5293 if (d->w == 1)
5294 {
5295 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5296 {
5297 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5298 return D_CLOSE;
5299 }
5300 }
5301
5302 if(msg==MSG_DRAW)
5303 {
5304 switch(d->w)
5305 {
5306 case 0:
5307 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5308 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5309 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5310 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5311 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5312 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5313 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5314 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5315 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5316 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5317 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5318 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5319 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5320 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5321 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5322 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5323 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5324 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5325 break;
5326
5327 case 1:
5328 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5329 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5330 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5331 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5332 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5333 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5334 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5335 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5336 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5337 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5338 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5339 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5340 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5341 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5342 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5343 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5344 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5345 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5346 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5347 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5348 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5349 break;
5350
5351 case 2:
5352 sprintf(str_a," %3d",midi_volume);
5353 sprintf(str_l," %3d",emusic_volume);
5354 sprintf(str_r," %3d",sfx_volume);
5355 strcpy(str_s,pan_str[pan_style]);
5356 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5357 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5358 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5359 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5360 break;
5361 }
5362 }
5363
5364 return D_O_K;
5365 }
5366
5367 int32_t set_vol(void *dp3, int32_t d2)
5368 {
5369 switch(((int32_t*)dp3)[0])
5370 {
5371 case 0:
5372 midi_volume = zc_min(d2<<3,255);
5373 break;
5374
5375 case 1:
5376 digi_volume = zc_min(d2<<3,255);
5377 break;
5378
5379 case 2:
5380 emusic_volume = zc_min(d2<<3,255);
5381 break;
5382
5383 case 3:
5384 sfx_volume = zc_min(d2<<3,255);
5385 break;
5386 }
5387
5388 // text_mode(vc(11));
5389 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5390 return D_O_K;
5391 }
5392
5393 int32_t set_pan(void *dp3, int32_t d2)
5394 {
5395 pan_style = vbound(d2,0,3);
5396 // text_mode(vc(11));
5397 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5398 return D_O_K;
5399 }
5400
5401 static int32_t gamepad_joys_list[] =
5402 {
5403 61,
5404 -1
5405 };
5406
5407 static int32_t gamepad_btn_list[] =
5408 {
5409 6,
5410 7,8,9,10,11,12,13,14,15,16,17,
5411 18,19,20,21,22,23,24,25,26,27,28,
5412 29,30,31,32,33,34,35,36,37,38,39,
5413 -1
5414 };
5415
5416 static int32_t gamepad_dirs_list[] =
5417 {
5418 40,41,42,43,
5419 44,45,46,47,
5420 48,49,50,51,
5421 52,53,54,55,
5422 56,57,58,59,
5423 60,
5424 -1
5425 };
5426
5427 static TABPANEL gamepad_tabs[] =
5428 {
5429 // (text)
5430 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5431 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5432 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5433 { NULL, 0, NULL, 0, NULL }
5434 };
5435
5436 const char *joy_list(int32_t index, int32_t *list_size)
5437 {
5438 if (index == -1)
5439 {
5440 *list_size = al_get_num_joysticks();
5441 return NULL;
5442 }
5443
5444 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5445 if (!joy)
5446 {
5447 return "?";
5448 }
5449
5450 return al_get_joystick_name(joy);
5451 }
5452
5453 418 static ListData joy__list(joy_list, &font);
5454
5455 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5456 {
5457 int32_t d2 = d->d2;
5458 int32_t ret = jwin_droplist_proc(msg,d,c);
5459
5460 if(d2!=d->d2)
5461 {
5462 joystick_index = d->d2;
5463 ret |= D_REDRAW_ALL;
5464 }
5465
5466 return ret;
5467 }
5468
5469 static DIALOG gamepad_dlg[] =
5470 {
5471 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5472 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5473 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5474 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5475 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5476 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5477 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5478 // 6
5479 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5480 // 7
5481 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5482 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5483 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5484 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5485 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5486 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5487 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5488 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5489 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5490 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5491 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5492 // 18
5493 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5494 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5495 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5496 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5497 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5498 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5499 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5500 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5501 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5502 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5503 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5504 // 29
5505 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5506 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5507 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5508 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5509 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5510 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5511 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5512 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5513 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5514 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5515 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5516 // 40
5517 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5518 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5519 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5520 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5521 // 44
5522 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5523 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5524 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5525 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5526 // 48
5527 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5528 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5529 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5530 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5531 // 52
5532 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5533 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5534 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5535 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5536 // 56
5537 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5538 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5539 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5540 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5541 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5542
5543 // 61
5544 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5545
5546 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5547 };
5548
5549 static int32_t keyboard_keys_list[] =
5550 {
5551 6,7,8,9,10,
5552 11,12,13,14,15,16,17,18,19,20,
5553 21,22,23,24,25,26,27,28,29,30,
5554 31,32,33,34,35,36,37,38,39,40,
5555 -1
5556 };
5557
5558 static int32_t keyboard_dirs_list[] =
5559 {
5560 41,42,43,44,
5561 45,46,47,48,
5562 49,50,51,52,
5563 53,54,55,56,
5564 -1
5565 };
5566
5567 static int32_t keyboard_mods_list[] =
5568 {
5569 57,58,59,60,
5570 61,62,63,64,
5571 65,66,67,68,
5572 69,70,71,72,
5573 -1
5574 };
5575
5576 static TABPANEL keyboard_control_tabs[] =
5577 {
5578 // (text)
5579 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5580 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5581 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5582 { NULL, 0, NULL, 0, NULL }
5583 };
5584
5585 static DIALOG keyboard_control_dlg[] =
5586 {
5587 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5588 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5589 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5590 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5591 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5592 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5593 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5594 // Keys
5595 // 6
5596 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5597 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5598 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5599 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5600 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5601 // 11
5602 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5603 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5604 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5605 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5606 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5607 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5608 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5609 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5610 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5611 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5612 // 21
5613 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5614 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5615 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5616 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5617 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5618 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5619 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5620 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5621 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5622 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5623 // 31
5624 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5625 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5626 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5627 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5628 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5629 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5630 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5631 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5632 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5633 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5634 // Dirs
5635 // 41
5636 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5637 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5638 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5639 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5640 // 45
5641 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5642 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5643 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5644 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5645 // 49
5646 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5647 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5648 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5649 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5650 // 53
5651 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5652 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5653 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5654 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5655 // Mods
5656 // 57
5657 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5658 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5659 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5660 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5661 // 61
5662 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5663 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5664 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5665 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5666 // 65
5667 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5668 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5669 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5670 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5671 // 69
5672 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5673 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5674 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5675 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5676 // 73
5677 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5678 };
5679
5680 int32_t midi_dp[3] = {0,0,0};
5681 int32_t emus_dp[3] = {2,0,0};
5682 int32_t sfx_dp[3] = {3,0,0};
5683 int32_t pan_dp[3] = {0,0,0};
5684
5685 static DIALOG sound_dlg[] =
5686 {
5687 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5688 418 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5689 418 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5690 418 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5691 418 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5692 418 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5693 418 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5694 418 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5695 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5696 418 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5697 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5698 // 10
5699 418 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5700 418 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5701 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5703 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5704 418 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5705 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5706 418 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5707 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5708 418 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5709 //20
5710 418 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5711 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5712 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5713 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5714 418 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5715 418 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5716 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5717 418 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5718 418 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5719 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5720 //30
5721 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5722 418 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5723 418 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5724 };
5725
5726 char zc_builddate[80];
5727 char zc_aboutstr[80];
5728
5729 static DIALOG about_dlg[] =
5730 {
5731 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5732 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5733 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5734 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5735 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5736 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5737 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5738 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5739 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5740 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5741 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5742 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5743 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5744 };
5745
5746
5747 static DIALOG quest_dlg[] =
5748 {
5749 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5750 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5751 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5752 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5753 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5754 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5755 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5756 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5757 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5758 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5759 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5760 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5761 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5762 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5763 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5764 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5765 };
5766
5767 static DIALOG triforce_dlg[] =
5768 {
5769 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5770 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5771 // 1
5772 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5773 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5774 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5775 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5776 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5777 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5778 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5779 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5780 // 9
5781 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5782 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5783 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5784 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5785 };
5786
5787 int32_t onToggleRecordingNewSaves()
5788 {
5789 if (zc_get_config("zeldadx", "replay_new_saves", false))
5790 {
5791 zc_set_config("zeldadx", "replay_new_saves", false);
5792 }
5793 else
5794 {
5795 zc_set_config("zeldadx", "replay_new_saves", true);
5796 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5797 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5798 }
5799 return D_O_K;
5800 }
5801
5802 #ifdef HAS_CURL
5803 int32_t onToggleAutoUploadReplays()
5804 {
5805 if (zc_get_config("zeldadx", "replay_upload", false))
5806 {
5807 zc_set_config("zeldadx", "replay_upload", false);
5808 }
5809 else
5810 {
5811 zc_set_config("zeldadx", "replay_upload", true);
5812 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5813 " preventing bugs and simplifying bug reports.",
5814 "Upload will happen no more than once a week when closing ZC",
5815 "OK",NULL,13,27,get_zc_font(font_lfont));
5816
5817 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5818 onToggleRecordingNewSaves();
5819 }
5820 return D_O_K;
5821 }
5822
5823 int32_t onUploadReplays()
5824 {
5825 if(jwin_alert3(
5826 "Upload replays",
5827 "Upload your replays now to assist in development?",
5828 NULL,
5829 NULL,
5830 "&Yes",
5831 "&No",
5832 NULL,
5833 'y',
5834 'n',
5835 0,
5836 get_zc_font(font_lfont)) == 1)
5837 {
5838 int num_uploaded = replay_upload();
5839 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5840 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5841 }
5842 return D_O_K;
5843 }
5844
5845 int32_t onClearUploadCache()
5846 {
5847 if(jwin_alert3(
5848 "Upload replays",
5849 "Clear the upload cache?",
5850 "This simply deletes replays/state.json. There's no harm in doing this, but",
5851 "likely is not necessary.",
5852 "&Yes",
5853 "&No",
5854 NULL,
5855 'y',
5856 'n',
5857 0,
5858 get_zc_font(font_lfont)) == 1)
5859 {
5860 replay_upload_clear_cache();
5861 }
5862 return D_O_K;
5863 }
5864 #endif
5865
5866 int32_t onToggleSnapshotAllFrames()
5867 {
5868 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5869 return D_O_K;
5870 }
5871
5872 int32_t onStopReplayOrRecord()
5873 {
5874 if (replay_is_replaying())
5875 {
5876 replay_quit();
5877 }
5878 else if (replay_get_mode() == ReplayMode::Record)
5879 {
5880 if (!replay_get_meta_bool("test_mode"))
5881 {
5882 jwin_alert("Recording", "You cannot stop recording a save file.",
5883 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5884 return D_CLOSE;
5885 }
5886
5887 if (jwin_alert("Stop Recording",
5888 "Save replay to disk and stop recording?",
5889 "This will stop the recording.",
5890 NULL,
5891 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5892 return D_CLOSE;
5893
5894 replay_save();
5895 replay_stop();
5896 }
5897 return D_O_K;
5898 }
5899
5900 static int32_t handle_on_load_replay(ReplayMode mode)
5901 {
5902 bool ctrl = CHECK_CTRL_CMD;
5903 if (Playing)
5904 {
5905 if (jwin_alert("Replay - Warning!",
5906 "Loading a replay will exit the current game.",
5907 "All unsaved progress will be lost.",
5908 "Do you wish to continue?",
5909 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5910 return D_CLOSE;
5911 }
5912
5913 std::string mode_string = replay_mode_to_string(mode);
5914 mode_string[0] = std::toupper(mode_string[0]);
5915
5916 std::string line_1 = "Select a replay file to play back.";
5917 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5918 std::string line_3 = "You can stop the replay and take over manually any time.";
5919 if (mode == ReplayMode::Update)
5920 {
5921 line_1 = "Select a replay file to update.";
5922 line_2 = "WARNING: be sure to back up the zplay file";
5923 line_3 = "and verify that the updated replay works as expected!";
5924 }
5925
5926 if (jwin_alert(mode_string.c_str(),
5927 line_1.c_str(),
5928 line_2.c_str(),
5929 line_3.c_str(),
5930 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5931 {
5932 std::string replay_path = "replays/";
5933 if(ctrl && devpwd())
5934 replay_path = "../../tests/replays/";
5935 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5936 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5937 replay_path = *result;
5938 else
5939 return D_CLOSE;
5940
5941 replay_quit();
5942 load_replay_file_deferred(mode, replay_path);
5943 Quit = qRESET;
5944 return D_CLOSE;
5945 }
5946 return D_O_K;
5947 }
5948
5949 int32_t onLoadReplay()
5950 {
5951 return handle_on_load_replay(ReplayMode::Replay);
5952 }
5953
5954 int32_t onLoadReplayAssert()
5955 {
5956 return handle_on_load_replay(ReplayMode::Assert);
5957 }
5958
5959 int32_t onLoadReplayUpdate()
5960 {
5961 return handle_on_load_replay(ReplayMode::Update);
5962 }
5963
5964 int32_t onSaveReplay()
5965 {
5966 if (replay_get_mode() == ReplayMode::Record)
5967 {
5968 if (!replay_get_meta_bool("test_mode"))
5969 {
5970 if (jwin_alert("Save Replay",
5971 "This will save a copy of the replay up to this point.",
5972 "The official replay file will be untouched.",
5973 "Do you wish to continue?",
5974 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5975 {
5976 return D_CLOSE;
5977 }
5978
5979 std::string replay_path = replay_get_replay_path().string();
5980 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5981 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5982 replay_path = *result;
5983 else
5984 return D_CLOSE;
5985
5986 if (fileexists(replay_path.c_str()))
5987 {
5988 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5989 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5990 return D_CLOSE;
5991 }
5992
5993 replay_save(replay_path);
5994 }
5995 else
5996 {
5997 replay_save();
5998 }
5999 }
6000 return D_O_K;
6001 }
6002
6003 enum
6004 {
6005 MENUID_REPLAY_RECORDNEW,
6006 MENUID_REPLAY_STOP,
6007 MENUID_REPLAY_SAVE,
6008 MENUID_REPLAY_SNAP_ALL,
6009 MENUID_REPLAY_AUTOUPLOAD,
6010 MENUID_REPLAY_UPLOAD,
6011 MENUID_REPLAY_CLEARUPLOADCACHE,
6012 };
6013
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu replay_menu
6014 5434 {
6015
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
6016
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
6017
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6018
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Load replay", onLoadReplay },
6019
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Load replay (assert)", onLoadReplayAssert },
6020
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Load replay (update)", onLoadReplayUpdate },
6021
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6022
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6023 #ifdef HAS_CURL
6024
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
6025
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6026
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6027
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6028 #endif
6029 };
6030
6031 static DIALOG credits_dlg[] =
6032 {
6033 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6034 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6035 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6036 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6037 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6038 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6039 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6040 };
6041
6042 418 static ListData dmap_list(dmaplist, &font);
6043
6044 static DIALOG goto_dlg[] =
6045 {
6046 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6047 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6048 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6049 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6050 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6051 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6052 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6053 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6054 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6055 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6056 };
6057
6058 int32_t onGoTo()
6059 {
6060 bool music = false;
6061 music = music;
6062 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6063
6064 goto_dlg[0].dp2=get_zc_font(font_lfont);
6065 goto_dlg[4].d2=cheat_goto_dmap;
6066 goto_dlg[6].dp=cheat_goto_screen_str;
6067
6068 clear_keybuf();
6069
6070 large_dialog(goto_dlg);
6071
6072 if(do_zqdialog(goto_dlg,4)==1)
6073 {
6074 int dmap = goto_dlg[4].d2;
6075 int screen = zc_xtoi(cheat_goto_screen_str);
6076 int adjusted_screen = screen + DMaps[dmap].xoff;
6077 if (adjusted_screen < 0 || adjusted_screen >= 128)
6078 {
6079 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6080 }
6081 else
6082 {
6083 cheats_enqueue(Cheat::GoTo, dmap, screen);
6084 }
6085 };
6086
6087 return D_O_K;
6088 }
6089
6090 int32_t onGoToComplete()
6091 {
6092 if(!Playing)
6093 {
6094 return D_O_K;
6095 }
6096
6097 enter_sys_pal();
6098 music_pause();
6099 pause_all_sfx();
6100 onGoTo();
6101 eat_buttons();
6102
6103 zc_readrawkey(KEY_ESC);
6104
6105 exit_sys_pal();
6106 music_resume();
6107 resume_all_sfx();
6108 return D_O_K;
6109 }
6110
6111 int32_t onCredits()
6112 {
6113 return D_O_K;
6114 }
6115
6116 const char *midilist(int32_t index, int32_t *list_size)
6117 {
6118 if(index<0)
6119 {
6120 *list_size=0;
6121
6122 for(int32_t i=0; i<MAXMIDIS; i++)
6123 if(tunes[i].data)
6124 ++(*list_size);
6125
6126 return NULL;
6127 }
6128
6129 int32_t i=0,m=0;
6130
6131 while(m<=index && i<=MAXMIDIS)
6132 {
6133 if(tunes[i].data)
6134 ++m;
6135
6136 ++i;
6137 }
6138
6139 --i;
6140
6141 if(i==MAXMIDIS && m<index)
6142 return "(null)";
6143
6144 return tunes[i].title;
6145 }
6146
6147 /* ------- MIDI info stuff -------- */
6148
6149 char *text;
6150 midi_info *zmi;
6151 bool dialog_running;
6152 bool listening;
6153
6154 void get_info(int32_t index);
6155
6156 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6157 {
6158 int32_t d2 = d->d2;
6159 int32_t ret = jwin_droplist_proc(msg,d,c);
6160
6161 if(d2!=d->d2)
6162 {
6163 get_info(d->d2);
6164 }
6165
6166 return ret;
6167 }
6168
6169 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6170 {
6171 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6172
6173 int32_t ret = jwin_button_proc(msg,d,c);
6174
6175 if(ret == D_CLOSE)
6176 {
6177 // get current midi index
6178 int32_t index = (d+(d->d1))->d2;
6179 int32_t i=0, m=0;
6180
6181 while(m<=index && i<=MAXMIDIS)
6182 {
6183 if(tunes[i].data)
6184 ++m;
6185
6186 ++i;
6187 }
6188
6189 --i;
6190 jukebox(i);
6191 listening = true;
6192 ret = D_O_K;
6193 }
6194
6195 return ret;
6196 }
6197
6198 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6199 {
6200 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6201
6202 int32_t ret = jwin_button_proc(msg,d,c);
6203
6204 if(ret == D_CLOSE)
6205 {
6206 // get current midi index
6207 int32_t index = (d+(d->d1))->d2;
6208 int32_t i=0, m=0;
6209
6210 while(m<=index && i<=MAXMIDIS)
6211 {
6212 if(tunes[i].data)
6213 ++m;
6214
6215 ++i;
6216 }
6217
6218 --i;
6219
6220 char title[40] = "Save MIDI: ";
6221 static EXT_LIST list[] =
6222 {
6223 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6224 { NULL, NULL }
6225 };
6226
6227 strcpy(title+11, tunes[i].title);
6228 title[39] = '\0';
6229
6230 std::string fname;
6231 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6232 fname = *result;
6233 else
6234 goto done;
6235
6236 if(exists(fname.c_str()))
6237 {
6238 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6239 goto done;
6240 }
6241
6242 // save midi i
6243
6244 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6245 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6246
6247 done:
6248 chop_path(fname.data());
6249 ret = D_REDRAW;
6250 }
6251
6252 return ret;
6253 }
6254
6255 418 static ListData midi_list(midilist, &font);
6256
6257 static DIALOG midi_dlg[] =
6258 {
6259 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6260 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6261 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6262 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6263 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6264 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6265 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6266 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6267 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6268 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6269 };
6270
6271 void get_info(int32_t index)
6272 {
6273 int32_t i=0, m=0;
6274
6275 while(m<=index && i<=MAXMIDIS)
6276 {
6277 if(tunes[i].data)
6278 ++m;
6279
6280 ++i;
6281 }
6282
6283 --i;
6284
6285 if(i==MAXMIDIS && m<index)
6286 strcpy(text,"(null)");
6287 else
6288 {
6289 get_midi_info(tunes[i].data,zmi);
6290 get_midi_text(tunes[i].data,zmi,text);
6291 }
6292
6293 midi_dlg[0].dp2=get_zc_font(font_lfont);
6294 midi_dlg[3].dp = text;
6295 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6296 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6297
6298 if(dialog_running)
6299 {
6300 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6301 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6302 }
6303 }
6304
6305 int32_t onMIDICredits()
6306 {
6307 text = (char*)malloc(4096);
6308 zmi = (midi_info*)malloc(sizeof(midi_info));
6309
6310 if(!text || !zmi)
6311 {
6312 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6313 return D_O_K;
6314 }
6315
6316 bool do_pause_midi = midi_pos >= 0 && currmidi;
6317 auto restore_midi = currmidi;
6318 if(do_pause_midi)
6319 {
6320 paused_midi_pos = midi_pos;
6321 stop_midi();
6322 midi_suspended = midissuspHALTED;
6323 }
6324
6325 midi_dlg[0].dp2=get_zc_font(font_lfont);
6326 midi_dlg[2].d1 = 0;
6327 midi_dlg[2].d2 = 0;
6328 midi_dlg[4].flags = D_EXIT;
6329 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6330
6331 listening = false;
6332 dialog_running=false;
6333 get_info(0);
6334
6335 dialog_running=true;
6336
6337 large_dialog(midi_dlg);
6338
6339 do_zqdialog(midi_dlg,0);
6340 dialog_running=false;
6341
6342 if(listening)
6343 music_stop();
6344
6345 if(do_pause_midi)
6346 {
6347 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6348 midi_suspended = midissuspRESUME;
6349 currmidi = restore_midi;
6350 midi_pos = paused_midi_pos;
6351 }
6352
6353 if(text) free(text);
6354 if(zmi) free(zmi);
6355 return D_O_K;
6356 }
6357
6358 int32_t onAbout()
6359 {
6360 char buf1[80]={0};
6361 std::ostringstream oss;
6362 sprintf(buf1,"ZQuest Classic Player");
6363 oss << buf1 << '\n';
6364 sprintf(buf1,"Version: %s", getVersionString());
6365 oss << buf1 << '\n';
6366 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6367 oss << buf1 << '\n';
6368
6369 InfoDialog("About ZC", oss.str()).show();
6370 return D_O_K;
6371 }
6372
6373 int32_t onQuest()
6374 {
6375 char fname[100];
6376 strcpy(fname, get_filename(qstpath));
6377 quest_dlg[0].dp2=get_zc_font(font_lfont);
6378 quest_dlg[1].dp = fname;
6379
6380 if(QHeader.quest_number==0)
6381 sprintf(str_a,"Custom");
6382 else
6383 sprintf(str_a,"%d",QHeader.quest_number);
6384
6385 sprintf(str_s,"%s",QHeader.getVerStr());
6386
6387 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6388 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6389
6390 large_dialog(quest_dlg);
6391
6392 do_zqdialog(quest_dlg, 0);
6393 return D_O_K;
6394 }
6395
6396 void call_vidmode_dlg();
6397 int32_t onVidMode()
6398 {
6399 call_vidmode_dlg();
6400 return D_O_K;
6401 }
6402
6403 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6404 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6405 //Added an extra statement, so that if the key is cleared to 0, the cleared
6406 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6407
6408 void load_ukeys(int32_t* arr)
6409 {
6410 arr[ukey_a] = Akey;
6411 arr[ukey_b] = Bkey;
6412 arr[ukey_s] = Skey;
6413 arr[ukey_l] = Lkey;
6414 arr[ukey_r] = Rkey;
6415 arr[ukey_p] = Pkey;
6416 arr[ukey_ex1] = Exkey1;
6417 arr[ukey_ex2] = Exkey2;
6418 arr[ukey_ex3] = Exkey3;
6419 arr[ukey_ex4] = Exkey4;
6420 arr[ukey_du] = DUkey;
6421 arr[ukey_dd] = DDkey;
6422 arr[ukey_dl] = DLkey;
6423 arr[ukey_dr] = DRkey;
6424 arr[ukey_mod1a] = cheat_modifier_keys[0];
6425 arr[ukey_mod1b] = cheat_modifier_keys[1];
6426 arr[ukey_mod2a] = cheat_modifier_keys[2];
6427 arr[ukey_mod2b] = cheat_modifier_keys[3];
6428 };
6429
6430 static const char* ukey_names[] = {
6431 "A", "B", "Start", "L", "R", "Map",
6432 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6433 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6434 "Cheat Mod R1", "Cheat Mod R2",
6435 };
6436 std::string get_ukey_name(int32_t k)
6437 {
6438 if (k < num_ukey) return ukey_names[k];
6439 return "";
6440 }
6441
6442 int32_t onKeyboard()
6443 {
6444 int32_t a = Akey;
6445 int32_t b = Bkey;
6446 int32_t s = Skey;
6447 int32_t l = Lkey;
6448 int32_t r = Rkey;
6449 int32_t p = Pkey;
6450 int32_t ex1 = Exkey1;
6451 int32_t ex2 = Exkey2;
6452 int32_t ex3 = Exkey3;
6453 int32_t ex4 = Exkey4;
6454 int32_t du = DUkey;
6455 int32_t dd = DDkey;
6456 int32_t dl = DLkey;
6457 int32_t dr = DRkey;
6458 int32_t mod1a = cheat_modifier_keys[0];
6459 int32_t mod1b = cheat_modifier_keys[1];
6460 int32_t mod2a = cheat_modifier_keys[2];
6461 int32_t mod2b = cheat_modifier_keys[3];
6462 bool done=false;
6463 int32_t ret;
6464
6465 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6466
6467 large_dialog(keyboard_control_dlg);
6468
6469 while(!done)
6470 {
6471 ret = do_zqdialog(keyboard_control_dlg,3);
6472
6473 if(ret==3) // OK
6474 {
6475 int32_t ukeys[num_ukey];
6476 load_ukeys(ukeys);
6477 std::vector<std::string> uniqueError;
6478 for(int32_t q = 0; q < num_ukey; ++q)
6479 {
6480 for(int32_t p = q+1; p < num_ukey; ++p)
6481 {
6482 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6483 {
6484 char buf[64];
6485 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6486 std::string str(buf);
6487 uniqueError.push_back(str);
6488 }
6489 }
6490 }
6491 if(uniqueError.size() == 0)
6492 {
6493 done = true;
6494 save_control_configs(true);
6495 }
6496 else
6497 {
6498 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6499 box_out("Cannot have duplicate keybinds!"); box_eol();
6500 for(std::vector<std::string>::iterator it = uniqueError.begin();
6501 it != uniqueError.end(); ++it)
6502 {
6503 box_out((*it).c_str()); box_eol();
6504 }
6505 box_end(true);
6506 }
6507 }
6508 else // Cancel
6509 {
6510 Akey = a;
6511 Bkey = b;
6512 Skey = s;
6513 Lkey = l;
6514 Rkey = r;
6515 Pkey = p;
6516 Exkey1 = ex1;
6517 Exkey2 = ex2;
6518 Exkey3 = ex3;
6519 Exkey4 = ex4;
6520 DUkey = du;
6521 DDkey = dd;
6522 DLkey = dl;
6523 DRkey = dr;
6524 cheat_modifier_keys[0] = mod1a;
6525 cheat_modifier_keys[1] = mod1b;
6526 cheat_modifier_keys[2] = mod2a;
6527 cheat_modifier_keys[3] = mod2b;
6528
6529 done=true;
6530 }
6531
6532 rest(1);
6533 }
6534
6535 return D_O_K;
6536 }
6537
6538 int32_t onGamepad()
6539 {
6540 if (al_get_num_joysticks() == 0)
6541 {
6542 InfoDialog("ZC", "No gamepads detected.").show();
6543 return D_O_K;
6544 }
6545
6546 int32_t a = Abtn;
6547 int32_t b = Bbtn;
6548 int32_t s = Sbtn;
6549 int32_t l = Lbtn;
6550 int32_t r = Rbtn;
6551 int32_t m = Mbtn;
6552 int32_t p = Pbtn;
6553 int32_t ex1 = Exbtn1;
6554 int32_t ex2 = Exbtn2;
6555 int32_t ex3 = Exbtn3;
6556 int32_t ex4 = Exbtn4;
6557 int32_t up = DUbtn;
6558 int32_t down = DDbtn;
6559 int32_t left = DLbtn;
6560 int32_t right = DRbtn;
6561 int32_t joy = joystick_index;
6562 int32_t stick_1 = js_stick_1_x_stick;
6563 int32_t stick_2 = js_stick_2_x_stick;
6564
6565 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6566 if(analog_movement)
6567 gamepad_dlg[56].flags|=D_SELECTED;
6568 else
6569 gamepad_dlg[56].flags&=~D_SELECTED;
6570
6571 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6572 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6573 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6574 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6575 // requires remapping every time.
6576 if (joystick_index >= al_get_num_joysticks())
6577 joystick_index = 0;
6578 gamepad_dlg[61].d2 = joystick_index;
6579
6580 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6581 if (!gamepad_dlg_cur_joystick)
6582 {
6583 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6584 return D_CLOSE;
6585 }
6586
6587 large_dialog(gamepad_dlg);
6588
6589 int32_t ret = do_zqdialog(gamepad_dlg,4);
6590
6591 if(ret == 4) //OK
6592 {
6593 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6594 joystick_index = gamepad_dlg[61].d2;
6595 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6596 if (!gamepad_dlg_cur_joystick)
6597 {
6598 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6599 return D_CLOSE;
6600 }
6601 js_stick_1_y_stick = js_stick_1_x_stick;
6602 js_stick_2_y_stick = js_stick_2_x_stick;
6603 save_control_configs(false);
6604 }
6605 else //Cancel
6606 {
6607 Abtn = a;
6608 Bbtn = b;
6609 Sbtn = s;
6610 Lbtn = l;
6611 Rbtn = r;
6612 Mbtn = m;
6613 Pbtn = p;
6614 Exbtn1 = ex1;
6615 Exbtn2 = ex2;
6616 Exbtn3 = ex3;
6617 Exbtn4 = ex4;
6618 DUbtn = up;
6619 DDbtn = down;
6620 DLbtn = left;
6621 DRbtn = right;
6622 joystick_index = joy;
6623 js_stick_1_x_stick = stick_1;
6624 js_stick_2_x_stick = stick_2;
6625 }
6626
6627 return D_O_K;
6628 }
6629
6630 int32_t onCheatKeys()
6631 {
6632 int32_t oldcheats[Cheat::Last][2];
6633 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6634
6635 bool done=false;
6636
6637 while(!done)
6638 {
6639 bool confirm = false;
6640 CheatKeysDialog(&confirm).show();
6641 if(confirm) // OK
6642 {
6643 std::vector<std::string> uniqueError;
6644 char buf[512];
6645 for(size_t q = 1; q < Cheat::Last; ++q)
6646 {
6647 if(cheatkeys[q][1] && !cheatkeys[q][0])
6648 {
6649 cheatkeys[q][0] = cheatkeys[q][1];
6650 cheatkeys[q][1] = 0;
6651 }
6652 }
6653 for(size_t q = 1; q < Cheat::Last; ++q)
6654 {
6655 if(!bindable_cheat((Cheat)q)) continue;
6656 for(size_t p = q+1; p < Cheat::Last; ++p)
6657 {
6658 if(!bindable_cheat((Cheat)p)) continue;
6659 for(size_t q2 = 0; q2 <= 1; ++q2)
6660 for(size_t p2 = 0; p2 <= 1; ++p2)
6661 {
6662 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6663 {
6664 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6665 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6666 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6667 get_keystr(cheatkeys[q][q2])));
6668 }
6669 }
6670 }
6671 }
6672 if(uniqueError.size() == 0)
6673 {
6674 done = true;
6675 save_cheatkeys();
6676 }
6677 else
6678 {
6679 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6680 box_out("Cannot have duplicate keybinds!"); box_eol();
6681 for(std::vector<std::string>::iterator it = uniqueError.begin();
6682 it != uniqueError.end(); ++it)
6683 {
6684 box_out((*it).c_str()); box_eol();
6685 }
6686 box_end(true);
6687 }
6688 }
6689 else // Cancel
6690 {
6691 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6692 done=true;
6693 }
6694 rest(1);
6695 }
6696
6697 return D_O_K;
6698 }
6699
6700 int32_t onSound()
6701 {
6702 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6703 {
6704 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6705 {
6706 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6707 }
6708 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6709 {
6710 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6711 }
6712 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6713 {
6714 emusic_volume = (int32_t)FFCore.usr_music_volume;
6715 }
6716 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6717 {
6718 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6719 }
6720 }
6721 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6722 {
6723 pan_style = (int32_t)FFCore.usr_panstyle;
6724 }
6725
6726 int32_t m = midi_volume;
6727 int32_t e = emusic_volume;
6728 int32_t s = sfx_volume;
6729 int32_t p = pan_style;
6730 pan_style = vbound(pan_style,0,3);
6731
6732 sound_dlg[0].dp2=get_zc_font(font_lfont);
6733
6734 large_dialog(sound_dlg);
6735
6736 midi_dp[1] = sound_dlg[6].x;
6737 midi_dp[2] = sound_dlg[6].y;
6738 emus_dp[1] = sound_dlg[8].x;
6739 emus_dp[2] = sound_dlg[8].y;
6740 sfx_dp[1] = sound_dlg[10].x;
6741 sfx_dp[2] = sound_dlg[10].y;
6742 pan_dp[1] = sound_dlg[11].x;
6743 pan_dp[2] = sound_dlg[11].y;
6744 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6745 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6746 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6747 sound_dlg[20].d2 = pan_style;
6748
6749 int32_t ret = do_zqdialog(sound_dlg,1);
6750
6751 if(ret==2)
6752 {
6753 master_volume(digi_volume,midi_volume);
6754 if (zcmusic)
6755 zcmusic_set_volume(zcmusic, emusic_volume);
6756
6757 int32_t temp_volume = sfx_volume;
6758 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6759 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6760 for(int32_t i=0; i<WAV_COUNT; ++i)
6761 {
6762 if(sfx_voice[i] >= 0)
6763 voice_set_volume(sfx_voice[i], temp_volume);
6764 }
6765 zc_set_config(sfx_sect,"midi",midi_volume);
6766 zc_set_config(sfx_sect,"sfx",sfx_volume);
6767 zc_set_config(sfx_sect,"emusic",emusic_volume);
6768 zc_set_config(sfx_sect,"pan",pan_style);
6769 }
6770 else
6771 {
6772 midi_volume = m;
6773 emusic_volume = e;
6774 sfx_volume = s;
6775 pan_style = p;
6776 }
6777
6778 return D_O_K;
6779 }
6780
6781 int32_t queding(char const* s1, char const* s2, char const* s3)
6782 {
6783 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6784 }
6785
6786 int32_t onQuit()
6787 {
6788 if(Playing)
6789 {
6790 int32_t ret=0;
6791
6792 if(get_qr(qr_NOCONTINUE))
6793 {
6794 if(standalone_mode)
6795 {
6796 ret=queding("End current game?",
6797 "The continue screen is disabled; the game",
6798 "will be reloaded from the last save.");
6799 }
6800 else
6801 {
6802 ret=queding("End current game?",
6803 "The continue screen is disabled. You will",
6804 "be returned to the file select screen.");
6805 }
6806 }
6807 else
6808 ret=queding("End current game?",NULL,NULL);
6809
6810 if(ret==1)
6811 {
6812 disableClickToFreeze=false;
6813 Quit=qQUIT;
6814
6815 // Trying to evade a door repair charge?
6816 if(repaircharge)
6817 {
6818 game->change_drupy(-repaircharge);
6819 repaircharge=0;
6820 }
6821
6822 return D_CLOSE;
6823 }
6824 }
6825
6826 return D_O_K;
6827 }
6828
6829 int32_t onTryQuitMenu()
6830 {
6831 return onTryQuit(true);
6832 }
6833
6834 int32_t onTryQuit(bool inMenu)
6835 {
6836 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6837 {
6838 if(active_cutscene.can_f6())
6839 {
6840 if(get_qr(qr_OLD_F6))
6841 {
6842 if(inMenu) onQuit();
6843 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6844 }
6845 else
6846 {
6847 disableClickToFreeze=false;
6848 GameFlags |= GAMEFLAG_TRYQUIT;
6849 }
6850 return D_CLOSE;
6851 }
6852 else active_cutscene.error();
6853 }
6854
6855 return D_O_K;
6856 }
6857
6858 int32_t onReset()
6859 {
6860 if(queding(" Reset system? ",NULL,NULL)==1)
6861 {
6862 disableClickToFreeze=false;
6863 Quit=qRESET;
6864 replay_quit();
6865 return D_CLOSE;
6866 }
6867
6868 return D_O_K;
6869 }
6870
6871 int32_t onExit()
6872 {
6873 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6874 {
6875 Quit=qEXIT;
6876 return D_CLOSE;
6877 }
6878
6879 return D_O_K;
6880 }
6881
6882 int32_t onDebug()
6883 {
6884 if(debug_enabled)
6885 set_debug(!get_debug());
6886 return D_O_K;
6887 }
6888
6889 int32_t onHeartBeep()
6890 {
6891 heart_beep=!heart_beep;
6892 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6893 return D_O_K;
6894 }
6895
6896 int32_t onSaveIndicator()
6897 {
6898 use_save_indicator = use_save_indicator ? 0 : 1;
6899 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6900 return D_O_K;
6901 }
6902
6903 int32_t onEpilepsy()
6904 {
6905 if(jwin_alert3(
6906 "Epilepsy Flash Reduction",
6907 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6908 "Disabling this will restore standard flash and wavy behaviour.",
6909 "Proceed?",
6910 "&Yes",
6911 "&No",
6912 NULL,
6913 'y',
6914 'n',
6915 0,
6916 get_zc_font(font_lfont)) == 1)
6917 {
6918 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6919 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6920 }
6921 return D_O_K;
6922 }
6923
6924 bool rc = false;
6925
6926 static DIALOG getnum_dlg[] =
6927 {
6928 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6929 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6930 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6931 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6932 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6933 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6934 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6935 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6936 };
6937
6938 int32_t getnumber(const char *prompt,int32_t initialval)
6939 {
6940 char buf[20];
6941 sprintf(buf,"%d",initialval);
6942 getnum_dlg[0].dp=(void *)prompt;
6943 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6944 getnum_dlg[2].dp=buf;
6945
6946 large_dialog(getnum_dlg);
6947
6948 if(do_zqdialog(getnum_dlg,2)==3)
6949 return atoi(buf);
6950
6951 return initialval;
6952 }
6953
6954 int32_t onLife()
6955 {
6956 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6957 cheats_enqueue(Cheat::Life, value);
6958 return D_O_K;
6959 }
6960
6961 int32_t onHeartC()
6962 {
6963 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6964 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6965 cheats_enqueue(Cheat::MaxLife, max_life);
6966 cheats_enqueue(Cheat::Life, life);
6967 return D_O_K;
6968 }
6969
6970 int32_t onMagicC()
6971 {
6972 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6973 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6974 cheats_enqueue(Cheat::MaxMagic, max_magic);
6975 cheats_enqueue(Cheat::Magic, magic);
6976 return D_O_K;
6977 }
6978
6979 int32_t onRupies()
6980 {
6981 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6982 cheats_enqueue(Cheat::Rupies, value);
6983 return D_O_K;
6984 }
6985
6986 int32_t onMaxBombs()
6987 {
6988 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6989 cheats_enqueue(Cheat::MaxBombs, value);
6990 cheats_enqueue(Cheat::Bombs, value);
6991 return D_O_K;
6992 }
6993
6994 int32_t onRefillLife()
6995 {
6996 cheats_enqueue(Cheat::Life, game->get_maxlife());
6997 return D_O_K;
6998 }
6999 int32_t onRefillMagic()
7000 {
7001 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
7002 return D_O_K;
7003 }
7004 int32_t onClock()
7005 {
7006 cheats_enqueue(Cheat::Clock);
7007 return D_O_K;
7008 }
7009
7010 int32_t onQstPath()
7011 {
7012 char initial_path[2048];
7013 chop_path(qstdir);
7014 strcpy(initial_path, qstdir);
7015
7016 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
7017 {
7018 char* path = result->data();
7019 chop_path(path);
7020 fix_filename_case(path);
7021 fix_filename_slashes(path);
7022 strcpy(qstdir,path);
7023 strcpy(qstpath,qstdir);
7024 zc_set_config("zeldadx","quest_dir",qstdir);
7025 flush_config_file();
7026 }
7027
7028 return D_O_K;
7029 }
7030
7031 #include "dialog/cheat_dialog.h"
7032 int32_t onCheat()
7033 {
7034 call_setcheat_dialog();
7035 game->set_cheat(maxcheat);
7036 if(cheat) game->did_cheat(true);
7037 return D_O_K;
7038 }
7039
7040 int32_t onCheatRupies()
7041 {
7042 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7043 return D_O_K;
7044 }
7045
7046 int32_t onCheatArrows()
7047 {
7048 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7049 return D_O_K;
7050 }
7051
7052 int32_t onCheatBombs()
7053 {
7054 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7055 return D_O_K;
7056 }
7057
7058 // *** screen saver
7059
7060 18525634 int32_t after_time()
7061 {
7062
1/2
✓ Branch 0 taken 18525634 times.
✗ Branch 1 not taken.
18525634 if(ss_enable == 0)
7063 return INT_MAX;
7064
7065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
18525634 if(ss_after <= 0)
7066 return 5 * 60;
7067
7068
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
18525634 if(ss_after <= 3)
7069 return ss_after * 15 * 60;
7070
7071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18525634 times.
18525634 if(ss_after <= 13)
7072 return (ss_after - 3) * 60 * 60;
7073
7074 18525634 return MAX_IDLE + 1;
7075 18525634 }
7076
7077 static const char *after_str[15] =
7078 {
7079 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7080 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7081 "Never"
7082 };
7083
7084 const char *after_list(int32_t index, int32_t *list_size)
7085 {
7086 if(index < 0)
7087 {
7088 *list_size = 15;
7089 return NULL;
7090 }
7091
7092 return after_str[index];
7093 }
7094
7095 418 static ListData after__list(after_list, &font);
7096
7097 static DIALOG scrsaver_dlg[] =
7098 {
7099 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7100 418 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7101 418 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7102 418 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7103 418 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7104 418 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7105 418 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7106 418 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7107 418 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7108 418 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7109 418 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7110 418 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7111 418 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7112 418 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7113 };
7114
7115 int32_t onScreenSaver()
7116 {
7117 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7118 int32_t oldcfgs[3];
7119 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7120 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7121 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7122
7123 large_dialog(scrsaver_dlg);
7124
7125 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7126
7127 if(ret == 8 || ret == 9)
7128 {
7129 ss_after = scrsaver_dlg[5].d1;
7130 ss_speed = scrsaver_dlg[6].d2;
7131 ss_density = scrsaver_dlg[7].d2;
7132 if(oldcfgs[0] != ss_after)
7133 zc_set_config(cfg_sect,"ss_after",ss_after);
7134 if(oldcfgs[1] != ss_speed)
7135 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7136 if(oldcfgs[2] != ss_density)
7137 zc_set_config(cfg_sect,"ss_density",ss_density);
7138 }
7139
7140 if(ret == 9)
7141 // preview Screen Saver
7142 {
7143 clear_keybuf();
7144 Matrix(ss_speed, ss_density, 30);
7145 system_pal(true);
7146 sys_mouse();
7147 }
7148
7149 return D_O_K;
7150 }
7151
7152 /***** Menus *****/
7153
7154 enum
7155 {
7156 MENUID_GAME_LOADQUEST,
7157 MENUID_GAME_ENDGAME,
7158 };
7159
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu game_menu
7160 3344 {
7161
3/6
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
418 { "&Continue","ESC", onContinue },
7162
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7163
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7164
3/6
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
418 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7165
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7166 #ifdef __EMSCRIPTEN__
7167 { "&Reset","F7", onReset },
7168 #elif defined(ALLEGRO_MACOSX)
7169 { "&Reset","F7", onReset },
7170 { "&Quit","F8", onExit },
7171 #else
7172
3/6
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
418 { "&Reset","F9", onReset },
7173
3/6
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
418 { "&Quit","F10", onExit },
7174 #endif
7175 };
7176
7177
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu snapshot_format_menu
7178 2926 {
7179
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7180
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7181
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7182
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7183
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7184
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7185 };
7186
7187
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu bottom_8_pixels_menu
7188 1672 {
7189
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7190
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "&On", std::bind(onSetBottom8Pixels, 1) },
7191
4/8
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 418 times.
✗ Branch 7 not taken.
418 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7192 };
7193
7194
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu controls_menu
7195 1672 {
7196
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Key&board...", onKeyboard },
7197
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Gamepad...", onGamepad },
7198
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Cheat Keys...", onCheatKeys },
7199 };
7200
7201
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu name_entry_mode_menu
7202 1672 {
7203
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Keyboard", onKeyboardEntry },
7204
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Letter Grid", onLetterGridEntry },
7205
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Extended Letter Grid", onExtLetterGridEntry },
7206 };
7207
7208 static void set_controls_menu_active()
7209 {
7210
7211 }
7212
7213 enum
7214 {
7215 MENUID_WINDOW_LOCK_ASPECT,
7216 MENUID_WINDOW_LOCK_INTSCALE,
7217 MENUID_WINDOW_SAVE_SIZE,
7218 MENUID_WINDOW_SAVE_POS,
7219 MENUID_WINDOW_STRETCH,
7220 };
7221
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu window_menu
7222 2508 {
7223
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7224
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7225
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7226
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7227
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7228 };
7229 void call_zc_options_dlg();
7230 enum
7231 {
7232 MENUID_OPTIONS_PAUSE_BG,
7233 MENUID_OPTIONS_EPILEPSYPROT,
7234 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7235 };
7236
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu options_menu
7237 3344 {
7238
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Name &Entry Mode", &name_entry_mode_menu },
7239
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "S&napshot Format", &snapshot_format_menu },
7240
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Window Settings", &window_menu },
7241
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7242
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7243
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7244
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "More Options", call_zc_options_dlg },
7245 };
7246 enum
7247 {
7248 MENUID_SETTINGS_CONTROLS,
7249 MENUID_SETTINGS_CAPFPS,
7250 MENUID_SETTINGS_SHOWFPS,
7251 MENUID_SETTINGS_SHOWTIME,
7252 MENUID_SETTINGS_CLICK_FREEZE,
7253 MENUID_SETTINGS_TRANSLAYERS,
7254 MENUID_SETTINGS_NESQUIT,
7255 MENUID_SETTINGS_VOLKEYS,
7256 MENUID_SETTINGS_HEARTBEEP,
7257 MENUID_SETTINGS_SAVEINDICATOR,
7258 MENUID_SETTINGS_DEBUG,
7259 };
7260
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu settings_menu
7261 7106 {
7262
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Sound...", onSound },
7263
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7264
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7265
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Options", &options_menu },
7266
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7267
3/6
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
418 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7268
3/6
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 418 times.
✗ Branch 5 not taken.
418 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7269
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7270
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7271
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7272
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7273
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7274
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7275
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7276
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7277
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7278 };
7279
7280 enum
7281 {
7282 MENUID_MISC_FULLSCREEN,
7283 MENUID_MISC_VIDMODE,
7284 MENUID_MISC_QUEST_INFO,
7285 MENUID_MISC_QUEST_DIR,
7286 MENUID_MISC_CONSOLE,
7287 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7288 };
7289
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu misc_menu
7290 6270 {
7291
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&About...", onAbout },
7292 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7293 // { "&Credits...", onCredits },
7294
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7295
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7296
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7297
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7298
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Quest &MIDI Info...", onMIDICredits },
7299
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7300
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7301
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Take &Snapshot F12", onSnapshot },
7302
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Sc&reen Saver...", onScreenSaver },
7303
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Save ZC Configuration", OnSaveZCConfig },
7304
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7305
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7306
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Clear Directory Cache", OnnClearQuestDir },
7307 };
7308
7309 enum
7310 {
7311 MENUID_REFILL_ARROWS,
7312 };
7313
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu refill_menu
7314 2508 {
7315
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Life", onRefillLife },
7316
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Magic", onRefillMagic },
7317
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Bombs", onCheatBombs },
7318
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Rupees", onCheatRupies },
7319
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7320 };
7321
7322 enum
7323 {
7324 MENUID_SHOW_L0,
7325 MENUID_SHOW_L1,
7326 MENUID_SHOW_L2,
7327 MENUID_SHOW_L3,
7328 MENUID_SHOW_L4,
7329 MENUID_SHOW_L5,
7330 MENUID_SHOW_L6,
7331 MENUID_SHOW_OVER,
7332 MENUID_SHOW_PUSH,
7333 MENUID_SHOW_FFC,
7334 MENUID_SHOW_SPR,
7335 MENUID_SHOW_SCRIPTNAME,
7336 MENUID_SHOW_SOLIDITY,
7337 MENUID_SHOW_HITBOX,
7338 MENUID_SHOW_EFFECT,
7339 };
7340
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu show_menu
7341 7942 {
7342
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7343
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7344
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7345
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7346
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7347
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7348
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7349
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7350
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7351
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7352
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7353
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7354
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7355
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 {},
7356
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7357
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7358
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7359
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Info Opacity", onShowInfoOpacity },
7360 };
7361
7362 enum
7363 {
7364 MENUID_CHEAT_CHOP_L1,
7365 MENUID_CHEAT_CHOP_L2,
7366 MENUID_CHEAT_CHOP_L3,
7367 MENUID_CHEAT_CHOP_L4,
7368 MENUID_CHEAT_INVULN,
7369 MENUID_CHEAT_NOCLIP,
7370 MENUID_CHEAT_IGNORESV,
7371 MENUID_CHEAT_GOFAST,
7372 };
7373
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 static NewMenu cheat_menu
7374 7106 {
7375
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Set &Cheat", onCheat },
7376
1/2
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
418 { MENUID_CHEAT_CHOP_L1 },
7377
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Re&fill", &refill_menu },
7378
1/2
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
418 { MENUID_CHEAT_CHOP_L2 },
7379
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7380
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Ma&x Bombs...", onMaxBombs },
7381
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Heart Containers...", onHeartC },
7382
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Magic Containers...", onMagicC },
7383
1/2
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
418 { MENUID_CHEAT_CHOP_L3 },
7384
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Hero Data...", onCheatConsole },
7385
1/2
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
418 { MENUID_CHEAT_CHOP_L4 },
7386
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7387
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7388
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7389
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Kill All Enemies", onKillCheat },
7390
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Trigger &Secrets", onSecretsCheat },
7391
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Trigger Secrets Perm", onSecretsCheatPerm },
7392
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Show/Hide Layer", &show_menu },
7393
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "Toggle &Light", onLightSwitch },
7394
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Goto Location...", onGoTo },
7395 };
7396
7397 #if DEVLEVEL > 0
7398 int32_t devLogging();
7399 int32_t devDebug();
7400 int32_t devTimestmp();
7401 #if DEVLEVEL > 1
7402 int32_t setCheat();
7403 #endif //DEVLEVEL > 1
7404 enum
7405 {
7406 MENUID_DEV_LOGGING,
7407 MENUID_DEV_DEBUG,
7408 MENUID_DEV_TIMESTAMP,
7409 MENUID_DEV_SETCHEAT,
7410 };
7411 static NewMenu dev_menu
7412 {
7413 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7414 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7415 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7416 #if DEVLEVEL > 1
7417 {},
7418 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7419 #endif //DEVLEVEL > 1
7420 };
7421 int32_t devLogging()
7422 {
7423 dev_logging = !dev_logging;
7424 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7425 return D_O_K;
7426 }
7427 // int32_t devDebug()
7428 // {
7429 // dev_debug = !dev_debug;
7430 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7431 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7432 // return D_O_K;
7433 // }
7434 int32_t devTimestmp()
7435 {
7436 dev_timestmp = !dev_timestmp;
7437 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7438 return D_O_K;
7439 }
7440 #if DEVLEVEL > 1
7441 int32_t setCheat()
7442 {
7443 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7444 return D_O_K;
7445 }
7446 #endif //DEVLEVEL > 1
7447 #endif //DEVLEVEL > 0
7448
7449 enum
7450 {
7451 MENUID_PLAYER_CHEAT,
7452 };
7453
1/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
418 TopMenu the_player_menu
7454 2508 {
7455
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Game", &game_menu },
7456
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Settings", &settings_menu },
7457
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7458
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&Replay", &replay_menu },
7459
2/4
✓ Branch 0 taken 418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
✗ Branch 3 not taken.
418 { "&ZC", &misc_menu },
7460 #if DEVLEVEL > 0
7461 { "&Dev", &dev_menu },
7462 #endif
7463 };
7464
7465 int32_t onPauseInBackground()
7466 {
7467 if(jwin_alert3(
7468 "Toggle Pause In Background",
7469 "This action will change whether ZC Player pauses when the window loses focus.",
7470 "",
7471 "Proceed?",
7472 "&Yes",
7473 "&No",
7474 NULL,
7475 'y',
7476 'n',
7477 0,
7478 get_zc_font(font_lfont)) == 1)
7479 {
7480 pause_in_background = pause_in_background ? 0 : 1;
7481 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7482 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7483 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7484 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7485 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7486 }
7487 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7488 return D_O_K;
7489 }
7490
7491 int32_t onKeyboardEntry()
7492 {
7493 NameEntryMode=0;
7494 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7495 return D_O_K;
7496 }
7497
7498 int32_t onLetterGridEntry()
7499 {
7500 NameEntryMode=1;
7501 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7502 return D_O_K;
7503 }
7504
7505 int32_t onExtLetterGridEntry()
7506 {
7507 NameEntryMode=2;
7508 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7509 return D_O_K;
7510 }
7511
7512 static BITMAP* oldscreen;
7513 int32_t onFullscreenMenu()
7514 {
7515 PALETTE oldpal;
7516 get_palette(oldpal);
7517
7518 fullscreen = !fullscreen;
7519 all_toggle_fullscreen(fullscreen);
7520 zc_set_config("zeldadx","fullscreen",fullscreen);
7521
7522 zc_set_palette(oldpal);
7523 gui_mouse_focus=0;
7524 extern int32_t switch_type;
7525 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7526 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7527 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7528 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7529 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7530 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7531
7532 return D_O_K;
7533 }
7534
7535 315 void fix_menu()
7536 {
7537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 315 times.
315 if(!debug_enabled)
7538 315 settings_menu.chop_index = 13;
7539 315 }
7540
7541 int32_t onSetSnapshotFormat(SnapshotType format)
7542 {
7543 SnapshotFormat = format;
7544 zc_set_config("zeldadx", "snapshot_format", format);
7545 snapshot_format_menu.select_only_index(format);
7546 return D_O_K;
7547 }
7548
7549 int32_t onSetBottom8Pixels(int option)
7550 {
7551 ShowBottomPixels = option;
7552 zc_set_config("zeldadx", "bottom_8_px", option);
7553 bottom_8_pixels_menu.select_only_index(option);
7554
7555 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7556 bool value = false;
7557 if (option == 0)
7558 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7559 else if (option == 1)
7560 value = false;
7561 else if (option == 2)
7562 value = true;
7563 enqueue_qr_change(qr, value);
7564
7565 return D_O_K;
7566 }
7567
7568 2921 void updateShowBottomPixels()
7569 {
7570 // It's too tricky the allow modifying the screen height between opening and closing the
7571 // active subscreen.
7572
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2895 times.
2921 if (subscreen_open)
7573 26 return;
7574
7575
1/2
✓ Branch 0 taken 2895 times.
✗ Branch 1 not taken.
2895 if (!GameLoaded)
7576 show_bottom_8px = false;
7577 else
7578 2895 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7579
7580 2895 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7581
2/2
✓ Branch 0 taken 2789 times.
✓ Branch 1 taken 106 times.
2895 if (framebuf->h != target_bitmap_height)
7582 {
7583 106 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7584 106 clear_bitmap(new_framebuf);
7585 106 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7586
7587 106 destroy_bitmap(framebuf);
7588 106 destroy_bitmap(script_menu_buf);
7589 106 destroy_bitmap(f6_menu_buf);
7590 106 destroy_bitmap(darkscr_bmp);
7591 106 destroy_bitmap(darkscr_bmp_trans);
7592
7593 106 framebuf = new_framebuf;
7594 106 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7595 106 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7596 106 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7597 106 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7598
7599 106 rti_game.a4_bitmap = framebuf;
7600 106 rti_game.set_size(framebuf->w, framebuf->h);
7601 106 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7602 106 al_destroy_bitmap(rti_game.bitmap);
7603 106 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7604 106 al_destroy_bitmap(rti_infolayer.bitmap);
7605 106 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7606 106 rti_infolayer.set_size(framebuf->w, framebuf->h);
7607 106 }
7608 2921 }
7609
7610 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7611 {
7612 PALETTE tmp;
7613
7614 for(int32_t i=0; i<256; i++)
7615 {
7616 tmp[i].r=r;
7617 tmp[i].g=g;
7618 tmp[i].b=b;
7619 }
7620
7621 fade_interpolate(src,tmp,dest,pos,from,to);
7622 }
7623
7624 47 void system_pal(bool force)
7625 {
7626
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
47 if(is_sys_pal && !force) return;
7627 47 is_sys_pal = true;
7628 47 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7629 47 hw_palette = &syspal;
7630 47 update_hw_pal = true;
7631 47 }
7632
7633 static uint32_t entered_sys_pal = 0;
7634 47 void enter_sys_pal()
7635 {
7636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if(is_sys_pal)
7637 {
7638 if(entered_sys_pal)
7639 ++entered_sys_pal;
7640 return;
7641 }
7642 47 sys_mouse();
7643 47 system_pal(true);
7644 47 ++entered_sys_pal;
7645 47 }
7646 47 void exit_sys_pal()
7647 {
7648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if(entered_sys_pal)
7649 {
7650
1/2
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
47 if(!--entered_sys_pal)
7651 {
7652 47 game_pal();
7653 47 game_mouse();
7654 47 }
7655 47 }
7656 47 }
7657
7658 void switch_out_callback()
7659 {
7660 if (pause_in_background && !MenuOpen)
7661 {
7662 System();
7663 }
7664 }
7665
7666 void switch_in_callback()
7667 {
7668 }
7669
7670 1161 void game_pal()
7671 {
7672 1161 is_sys_pal = false;
7673 1161 entered_sys_pal = 0;
7674 1161 hw_palette = &RAMpal;
7675 1161 update_hw_pal = true;
7676 1161 }
7677
7678 static char bar_str[] = "";
7679
7680 47 void music_pause()
7681 {
7682 //al_pause_duh(tmplayer);
7683 47 zcmusic_pause(zcmusic, ZCM_PAUSE);
7684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if(zcmixer->oldtrack)
7685 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7686 47 zc_midi_pause();
7687 47 }
7688
7689 void music_resume()
7690 {
7691 //al_resume_duh(tmplayer);
7692 zcmusic_pause(zcmusic, ZCM_RESUME);
7693 if (zcmixer->oldtrack)
7694 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7695 zc_midi_resume();
7696 }
7697
7698 7927 void music_stop()
7699 {
7700 //al_stop_duh(tmplayer);
7701 //unload_duh(tmusic);
7702 //tmusic=NULL;
7703 //tmplayer=NULL;
7704 7927 zcmusic_stop(zcmusic);
7705 7927 zcmusic_unload_file(zcmusic);
7706
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7927 times.
7927 if (zcmixer->oldtrack)
7707 {
7708 zcmusic_stop(zcmixer->oldtrack);
7709 zcmusic_unload_file(zcmixer->oldtrack);
7710 }
7711 7927 zcmixer->newtrack = NULL;
7712 7927 zc_stop_midi();
7713 7927 currmidi=-1;
7714 7927 }
7715
7716 bool reload_fonts = false;
7717 void System()
7718 {
7719 mouse_down = gui_mouse_b();
7720 music_pause();
7721 pause_all_sfx();
7722 MenuOpen = true;
7723 enter_sys_pal();
7724 // FONT *oldfont=font;
7725 // font=tfont;
7726
7727 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7728 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7729
7730 #if DEVLEVEL > 1
7731 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7732 #endif
7733 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7734 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7735 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7736 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7737 clear_keybuf();
7738
7739 clear_bitmap(menu_bmp);
7740 oldscreen = screen;
7741 screen = menu_bmp;
7742
7743 the_player_menu.reset_state();
7744 the_player_menu.position(0, 0);
7745
7746 bool running = true;
7747 bool esc = key[KEY_ESC] || cMbtn();
7748 bool autopop = esc;
7749 do
7750 {
7751 if(reload_fonts)
7752 {
7753 init_custom_fonts();
7754 clear_bitmap(menu_bmp);
7755 broadcast_dialog_message(MSG_DRAW, 0);
7756 reload_fonts = false;
7757 }
7758 if(handle_close_btn_quit())
7759 break;
7760
7761 //update submenus
7762 {
7763 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7764 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7765 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7766 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7767 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7768 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7769 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7770 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7771
7772 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7773 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7774 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7775 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7776 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7777
7778 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7779 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7780 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7781
7782 name_entry_mode_menu.select_only_index(NameEntryMode);
7783
7784 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7785 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7786
7787 bool nocheat = (replay_is_replaying() || !Playing
7788 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7789 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7790 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7791 cheat_menu.chop_index.reset();
7792 if(cheat < 4)
7793 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7794 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7795 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, walk_through_walls);
7796 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7797 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7798
7799 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7800 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7801 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7802 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7803 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7804 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7805 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7806 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7807 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7808 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7809 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7810 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7811 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7812 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7813 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7814
7815 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7816 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7817
7818 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7819 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7820
7821 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7822 #ifdef HAS_CURL
7823 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7824 #endif
7825 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7826 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7827 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7828
7829 snapshot_format_menu.select_only_index(SnapshotFormat);
7830 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7831 }
7832
7833 if(debug_enabled)
7834 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7835
7836 if(autopop)
7837 clear_keybuf();
7838 the_player_menu.run(true);
7839 if(autopop)
7840 {
7841 the_player_menu.pop_sub(0, &the_player_menu);
7842 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7843 autopop = false;
7844 update_hw_screen();
7845 }
7846
7847 update_hw_screen();
7848
7849 auto mb = gui_mouse_b();
7850 if(XOR(mb, mouse_down))
7851 {
7852 if(!the_player_menu.has_mouse())
7853 if(mb)
7854 break;
7855 mouse_down = mb;
7856 }
7857
7858 if(input_idle(true) > after_time())
7859 // run Screeen Saver
7860 {
7861 // Screen saver enabled for now.
7862 clear_keybuf();
7863 Matrix(ss_speed, ss_density, 0);
7864 system_pal(true);
7865 sys_mouse();
7866 }
7867
7868 poll_keyboard();
7869 if(esc)
7870 {
7871 if(!key[KEY_ESC])
7872 esc = false;
7873 }
7874
7875 if(keypressed() && !CHECK_ALT) //System hotkeys
7876 {
7877 auto c = peekkey();
7878 bool eatkey = true;
7879 switch(c>>8)
7880 {
7881 //Spare keys used by the menu
7882 case KEY_UP:
7883 case KEY_DOWN:
7884 case KEY_LEFT:
7885 case KEY_RIGHT:
7886 eatkey = false;
7887 break;
7888 case KEY_F1:
7889 onThrottleFPS();
7890 break;
7891 case KEY_F2:
7892 onShowFPS();
7893 break;
7894 case KEY_F6:
7895 onTryQuitMenu();
7896 break;
7897 #ifndef ALLEGRO_MACOSX
7898 case KEY_F9:
7899 onReset();
7900 break;
7901 case KEY_F10:
7902 onExit();
7903 break;
7904 #else
7905 case KEY_F7:
7906 onReset();
7907 break;
7908 case KEY_F8:
7909 onExit();
7910 break;
7911 #endif
7912 case KEY_F12:
7913 onSnapshot();
7914 break;
7915 case KEY_TAB:
7916 onDebug();
7917 break;
7918 case KEY_ESC:
7919 if(!esc)
7920 running = false;
7921 break;
7922 }
7923 if(eatkey)
7924 readkey();
7925 }
7926 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7927 break;
7928 }
7929 while(running);
7930
7931 screen = oldscreen;
7932
7933 mouse_down=gui_mouse_b();
7934 MenuOpen = false;
7935 if(Quit)
7936 {
7937 kill_sfx();
7938 music_stop();
7939 update_hw_screen();
7940 }
7941 else
7942 {
7943 music_resume();
7944 resume_all_sfx();
7945
7946 if(rc)
7947 ringcolor(false);
7948 }
7949 exit_sys_pal();
7950
7951 eat_buttons();
7952
7953 rc=false;
7954 clear_keybuf();
7955
7956 zc_init_apply_cheat_delta();
7957 }
7958
7959 315 void fix_dialogs()
7960 {
7961 315 jwin_center_dialog(about_dlg);
7962 315 jwin_center_dialog(gamepad_dlg);
7963 315 jwin_center_dialog(credits_dlg);
7964 315 jwin_center_dialog(gamemode_dlg);
7965 315 jwin_center_dialog(getnum_dlg);
7966 315 jwin_center_dialog(goto_dlg);
7967 315 jwin_center_dialog(keyboard_control_dlg);
7968 315 jwin_center_dialog(midi_dlg);
7969 315 jwin_center_dialog(quest_dlg);
7970 315 jwin_center_dialog(scrsaver_dlg);
7971 315 jwin_center_dialog(sound_dlg);
7972 315 jwin_center_dialog(triforce_dlg);
7973 315 }
7974
7975 4331 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7976 {
7977
3/4
✓ Branch 0 taken 4331 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4309 times.
✓ Branch 3 taken 22 times.
4331 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7978 }
7979
7980 294 int32_t get_emusic_volume()
7981 {
7982 294 int32_t temp_volume = emusic_volume;
7983
2/4
✓ Branch 0 taken 294 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 294 times.
✗ Branch 3 not taken.
294 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7984 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
294 if (!zcmusic)
7986 294 return temp_volume;
7987 return (temp_volume * zcmusic->fadevolume) / 10000;
7988 294 }
7989
7990 int32_t get_zcmusicpos()
7991 {
7992 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7993 return debugtracething;
7994 return 0;
7995 }
7996
7997 void set_zcmusicpos(int32_t position)
7998 {
7999 zcmusic_set_curpos(zcmusic, position);
8000 }
8001
8002 void set_zcmusicspeed(int32_t speed)
8003 {
8004 zcmusic_set_speed(zcmusic, speed);
8005 }
8006
8007 int32_t get_zcmusiclen()
8008 {
8009 return zcmusic_get_length(zcmusic);
8010 }
8011
8012 3 void set_zcmusicloop(double start, double end)
8013 {
8014 3 zcmusic_set_loop(zcmusic, start, end);
8015 3 }
8016
8017 64164 void jukebox(int32_t index,int32_t loop)
8018 {
8019
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if (is_headless())
8020 64164 return;
8021
8022 music_stop();
8023
8024 if(index<0) index=MAXMIDIS-1;
8025
8026 if(index>=MAXMIDIS) index=0;
8027
8028 music_stop();
8029
8030 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8031 // stuck notes when a song stops. This fixes it.
8032 if(strcmp(midi_driver->name, "DIGMID")==0)
8033 zc_set_volume(0, 0);
8034
8035 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8036 zc_play_midi(tunes[index].data,loop);
8037
8038 if(tunes[index].start>0)
8039 zc_midi_seek(tunes[index].start);
8040
8041 midi_loop_start = tunes[index].loop_start;
8042 midi_loop_end = tunes[index].loop_end;
8043
8044 currmidi=index;
8045 master_volume(digi_volume, midi_volume);
8046 //midi_paused=false;
8047 64164 }
8048
8049 64164 void jukebox(int32_t index)
8050 {
8051
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index<0) index=MAXMIDIS-1;
8052
8053
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index>=MAXMIDIS) index=0;
8054
8055 // do nothing if it's already playing
8056
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64164 if(index==currmidi && midi_pos>=0)
8057 {
8058 return;
8059 }
8060
8061 64164 jukebox(index,tunes[index].loop);
8062 64164 }
8063
8064 102 void play_DmapMusic()
8065 {
8066
1/2
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
102 if (is_headless())
8067 102 return;
8068
8069 static char tfile[2048];
8070 static int32_t ttrack=0;
8071 bool domidi=false;
8072
8073 int32_t fadeoutframes = 0;
8074 if (zcmusic != NULL)
8075 fadeoutframes = zcmusic->fadeoutframes;
8076
8077 if(DMaps[cur_dmap].tmusic[0]!=0)
8078 {
8079 if(zcmusic==NULL ||
8080 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8081 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8082 {
8083 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8084 {
8085 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8086 {
8087 if (zcmusic != NULL)
8088 {
8089 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8090 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8091 }
8092 }
8093 }
8094 else
8095 {
8096 if (zcmusic != NULL)
8097 {
8098 zcmusic_stop(zcmusic);
8099 zcmusic_unload_file(zcmusic);
8100 zcmusic = NULL;
8101 zcmixer->newtrack = NULL;
8102 }
8103
8104 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8105 zcmixer->newtrack = zcmusic;
8106
8107 if (zcmusic != NULL)
8108 {
8109 zc_stop_midi();
8110 strcpy(tfile, DMaps[cur_dmap].tmusic);
8111 zcmusic_play(zcmusic, emusic_volume);
8112 int32_t temptracks = 0;
8113 temptracks = zcmusic_get_tracks(zcmusic);
8114 temptracks = (temptracks < 2) ? 1 : temptracks;
8115 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8116 zcmusic_change_track(zcmusic, ttrack);
8117 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8118 }
8119 else
8120 {
8121 tfile[0] = 0;
8122 domidi = true;
8123 }
8124 }
8125 }
8126 }
8127 else
8128 {
8129 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8130 {
8131 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8132 }
8133 else
8134 {
8135 domidi = true;
8136 }
8137 }
8138
8139 if(domidi)
8140 {
8141 int32_t m=DMaps[cur_dmap].midi;
8142
8143 switch(m)
8144 {
8145 case 1:
8146 jukebox(ZC_MIDI_OVERWORLD);
8147 break;
8148
8149 case 2:
8150 jukebox(ZC_MIDI_DUNGEON);
8151 break;
8152
8153 case 3:
8154 jukebox(ZC_MIDI_LEVEL9);
8155 break;
8156
8157 default:
8158 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8159 jukebox(m+MIDIOFFSET_DMAP);
8160 else
8161 music_stop();
8162 }
8163 }
8164 102 }
8165
8166 35717 void playLevelMusic()
8167 {
8168
1/2
✓ Branch 0 taken 35717 times.
✗ Branch 1 not taken.
35717 if (is_headless())
8169 35717 return;
8170
8171 int32_t m=hero_scr->screen_midi;
8172
8173 switch(m)
8174 {
8175 case -2:
8176 music_stop();
8177 break;
8178
8179 case -1:
8180 play_DmapMusic();
8181 break;
8182
8183 case 1:
8184 jukebox(ZC_MIDI_OVERWORLD);
8185 break;
8186
8187 case 2:
8188 jukebox(ZC_MIDI_DUNGEON);
8189 break;
8190
8191 case 3:
8192 jukebox(ZC_MIDI_LEVEL9);
8193 break;
8194
8195 default:
8196 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8197 jukebox(m+MIDIOFFSET_MAPSCR);
8198 else
8199 music_stop();
8200 }
8201 35717 }
8202
8203 4331 void master_volume(int32_t dv,int32_t mv)
8204 {
8205
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2323 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 356 times.
✓ Branch 4 taken 2323 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 356 times.
4331 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8206
8207
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2327 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 327 times.
✓ Branch 4 taken 2327 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 327 times.
4331 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8208
8209
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4331 times.
✓ Branch 2 taken 4331 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4331 times.
4331 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8210 4331 int32_t temp_vol = midi_volume;
8211
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 315 times.
4331 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8212 315 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8213 4331 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8214 4331 }
8215
8216 // array of voices, one for each sfx sample in the data file
8217 // 0+ = voice #
8218 // -1 = voice not allocated
8219 315 void Z_init_sound()
8220 {
8221
2/2
✓ Branch 0 taken 80640 times.
✓ Branch 1 taken 315 times.
80955 for(int32_t i=0; i<WAV_COUNT; i++)
8222 80640 sfx_voice[i]=-1;
8223
8224 315 const char* midis[ZC_MIDI_COUNT] = {
8225 "assets/dungeon.mid",
8226 "assets/ending.mid",
8227 "assets/gameover.mid",
8228 "assets/level9.mid",
8229 "assets/overworld.mid",
8230 "assets/title.mid",
8231 "assets/triforce.mid",
8232 };
8233
2/2
✓ Branch 0 taken 2205 times.
✓ Branch 1 taken 315 times.
2520 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8234 {
8235 2205 tunes[i].data = load_midi(midis[i]);
8236
1/2
✓ Branch 0 taken 2205 times.
✗ Branch 1 not taken.
2205 if (!tunes[i].data)
8237 Z_error_fatal("Missing required file %s\n", midis[i]);
8238 2205 }
8239
8240
2/2
✓ Branch 0 taken 79380 times.
✓ Branch 1 taken 315 times.
79695 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8241 79380 tunes[ZC_MIDI_COUNT+j].data=NULL;
8242
8243 315 master_volume(digi_volume,midi_volume);
8244 315 }
8245
8246 // returns number of voices currently allocated
8247 int32_t sfx_count()
8248 {
8249 int32_t c=0;
8250
8251 for(int32_t i=0; i<WAV_COUNT; i++)
8252 if(sfx_voice[i]!=-1)
8253 ++c;
8254
8255 return c;
8256 }
8257
8258 // clean up finished samples
8259 18317026 void sfx_cleanup()
8260 {
8261
2/2
✓ Branch 0 taken 4689158656 times.
✓ Branch 1 taken 18317026 times.
4707475682 for(int32_t i=0; i<WAV_COUNT; i++)
8262
3/4
✓ Branch 0 taken 1267421 times.
✓ Branch 1 taken 4687891235 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267421 times.
4690426077 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8263 {
8264 1267421 deallocate_voice(sfx_voice[i]);
8265 1267421 sfx_voice[i]=-1;
8266 1267421 }
8267 18317026 }
8268
8269 1267586 SAMPLE* sfx_get_sample(int32_t index)
8270 {
8271 // check index
8272
2/4
✓ Branch 0 taken 1267586 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267586 times.
1267586 if (index<=0 || index>=WAV_COUNT)
8273 return nullptr;
8274
8275
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 821339 times.
1267586 if (sfxdat)
8276 {
8277
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8278 {
8279 446247 return (SAMPLE*)sfxdata[index].dat;
8280 }
8281 else
8282 {
8283 return (SAMPLE*)sfxdata[Z35].dat;
8284 }
8285 }
8286 else
8287 {
8288 821339 return &customsfxdata[index];
8289 }
8290
8291 return nullptr;
8292 1267586 }
8293
8294 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8295 // if a voice is already allocated (and/or playing), then it just returns true
8296 // Returns true: voice is allocated
8297 // false: unsuccessful
8298 1880999 bool sfx_init(int32_t index)
8299 {
8300 // check index
8301
3/4
✓ Branch 0 taken 1400306 times.
✓ Branch 1 taken 480693 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1400306 times.
1880999 if(index<=0 || index>=WAV_COUNT)
8302 480693 return false;
8303
8304
2/2
✓ Branch 0 taken 132780 times.
✓ Branch 1 taken 1267526 times.
1400306 if (sfx_voice[index] == -1)
8305 {
8306 1267526 SAMPLE* sample = sfx_get_sample(index);
8307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1267526 times.
1267526 if (!sample)
8308 return false;
8309
8310 1267526 sfx_voice[index] = allocate_voice(sample);
8311 1267526 }
8312
8313 1400306 return sfx_voice[index] != -1;
8314 1880999 }
8315
8316 int32_t sfx_get_default_freq(int32_t index)
8317 {
8318 if (sfxdat)
8319 {
8320 if (index < Z35)
8321 {
8322 return ((SAMPLE*)sfxdata[index].dat)->freq;
8323 }
8324 else
8325 {
8326 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8327 }
8328 }
8329 else
8330 {
8331 return customsfxdata[index].freq;
8332 }
8333 }
8334
8335 int32_t sfx_get_length(int32_t index)
8336 {
8337 if (sfxdat)
8338 {
8339 if (index < Z35)
8340 {
8341 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8342 }
8343 else
8344 {
8345 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8346 }
8347 }
8348 else
8349 {
8350 return int32_t(customsfxdata[index].len);
8351 }
8352 }
8353
8354 // plays an sfx sample
8355 1880999 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8356 {
8357
2/2
✓ Branch 0 taken 1400306 times.
✓ Branch 1 taken 480693 times.
1880999 if(!sfx_init(index))
8358 480693 return;
8359
1/2
✓ Branch 0 taken 1400306 times.
✗ Branch 1 not taken.
1400306 if (!is_headless())
8360 {
8361 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8362 voice_set_pan(sfx_voice[index], pan);
8363
8364 // Only used by ZScript currently
8365 if (freq <= -1)
8366 {
8367 freq = sfx_get_default_freq(index);
8368 }
8369 voice_set_frequency(sfx_voice[index], freq);
8370
8371 // Only used by ZScript currently
8372 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8373 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8374 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8375 voice_set_volume(sfx_voice[index], temp_volume);
8376
8377 int32_t pos = voice_get_position(sfx_voice[index]);
8378
8379 if (restart) voice_set_position(sfx_voice[index], 0);
8380
8381 if (pos <= 0)
8382 voice_start(sfx_voice[index]);
8383 }
8384
8385
3/4
✓ Branch 0 taken 865891 times.
✓ Branch 1 taken 534415 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 865891 times.
1400306 if (restart && replay_is_debug())
8386 {
8387 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8388 865891 const char* sfx_name = sfx_string[index];
8389
2/2
✓ Branch 0 taken 854091 times.
✓ Branch 1 taken 11800 times.
865891 if (strcmp(sfx_name, "Hero is hit") == 0)
8390 11800 sfx_name = "Player is hit";
8391
2/2
✓ Branch 0 taken 853964 times.
✓ Branch 1 taken 127 times.
854091 else if (strcmp(sfx_name, "Hero dies") == 0)
8392 127 sfx_name = "Player dies";
8393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865891 times.
865891 replay_step_comment(fmt::format("sfx {}", sfx_name));
8394 865891 }
8395 1880999 }
8396
8397 // true if sfx is allocated
8398 203255 bool sfx_allocated(int32_t index)
8399 {
8400
3/4
✓ Branch 0 taken 33546 times.
✓ Branch 1 taken 169709 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33546 times.
203255 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8401 }
8402
8403 // start it (in loop mode) if it's not already playing,
8404 // otherwise adjust it to play in loop mode -DD
8405 118481 void cont_sfx(int32_t index)
8406 {
8407
1/2
✓ Branch 0 taken 118481 times.
✗ Branch 1 not taken.
118481 if (is_headless())
8408 118481 return;
8409
8410 if(!sfx_init(index))
8411 {
8412 return;
8413 }
8414
8415 if(voice_get_position(sfx_voice[index])<=0)
8416 {
8417 voice_set_position(sfx_voice[index],0);
8418 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8419 voice_set_volume(sfx_voice[index], sfx_volume);
8420 voice_start(sfx_voice[index]);
8421 }
8422 else
8423 {
8424 adjust_sfx(index, 128, true);
8425 }
8426 118481 }
8427
8428 // adjust parameters while playing
8429 4948 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8430 {
8431
4/6
✓ Branch 0 taken 4511 times.
✓ Branch 1 taken 437 times.
✓ Branch 2 taken 4511 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4511 times.
4948 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8432 4948 return;
8433
8434 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8435 voice_set_pan(sfx_voice[index],pan);
8436 4948 }
8437
8438 // pauses a voice
8439 3254 void pause_sfx(int32_t index)
8440 {
8441
3/6
✓ Branch 0 taken 3254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3254 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3254 times.
3254 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8442 voice_stop(sfx_voice[index]);
8443 3254 }
8444
8445 // resumes a voice
8446 1372 void resume_sfx(int32_t index)
8447 {
8448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1372 times.
1372 if (is_headless())
8449 1372 return;
8450
8451 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8452 voice_start(sfx_voice[index]);
8453 1372 }
8454
8455 // pauses all active voices
8456 1064 void pause_all_sfx()
8457 {
8458
2/2
✓ Branch 0 taken 272384 times.
✓ Branch 1 taken 1064 times.
273448 for(int32_t i=0; i<WAV_COUNT; i++)
8459
2/2
✓ Branch 0 taken 272382 times.
✓ Branch 1 taken 2 times.
272386 if(sfx_voice[i]!=-1)
8460 2 voice_stop(sfx_voice[i]);
8461 1064 }
8462
8463 // resumes all paused voices
8464 1017 void resume_all_sfx()
8465 {
8466
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8467
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8468 voice_start(sfx_voice[i]);
8469 1017 }
8470
8471 // stops an sfx and deallocates the voice
8472 14624266 void stop_sfx(int32_t index)
8473 {
8474
3/4
✓ Branch 0 taken 14374733 times.
✓ Branch 1 taken 249533 times.
✓ Branch 2 taken 14374733 times.
✗ Branch 3 not taken.
14624266 if(index<=0 || index>=WAV_COUNT)
8475 249533 return;
8476
8477
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 14374686 times.
14374733 if(sfx_voice[index]!=-1)
8478 {
8479 47 deallocate_voice(sfx_voice[index]);
8480 47 sfx_voice[index]=-1;
8481 47 }
8482 14624266 }
8483
8484 // Stops SFX played by Hero's item of the given family
8485 163371 void stop_item_sfx(int32_t family)
8486 {
8487 163371 int32_t id=current_item_id(family);
8488
8489
2/2
✓ Branch 0 taken 162269 times.
✓ Branch 1 taken 1102 times.
163371 if(id<0)
8490 162269 return;
8491
8492 1102 stop_sfx(itemsbuf[id].usesound);
8493 163371 }
8494
8495 9364 void kill_sfx()
8496 {
8497
2/2
✓ Branch 0 taken 2397184 times.
✓ Branch 1 taken 9364 times.
2406548 for(int32_t i=0; i<WAV_COUNT; i++)
8498
2/2
✓ Branch 0 taken 2397126 times.
✓ Branch 1 taken 58 times.
2397242 if(sfx_voice[i]!=-1)
8499 {
8500 58 deallocate_voice(sfx_voice[i]);
8501 58 sfx_voice[i]=-1;
8502 58 }
8503 9364 }
8504
8505 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8506 1201076 int32_t pan(int32_t x)
8507 {
8508
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1201076 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1201076 switch(pan_style)
8509 {
8510 // MONO
8511 case 0:
8512 return 128;
8513
8514 // 1/2
8515 case 1:
8516 1201076 x -= viewport.x;
8517 1201076 return vbound((x>>1)+68,0,255);
8518
8519 // 3/4
8520 case 2:
8521 x -= viewport.x;
8522 return vbound(((x*3)>>2)+36,0,255);
8523
8524 // FULL
8525 case 3:
8526 default:
8527 x -= viewport.x;
8528 return vbound(x,0,255);
8529 }
8530 1201076 }
8531
8532 50443078 bool joybtn(int32_t b)
8533 {
8534
1/2
✓ Branch 0 taken 50443078 times.
✗ Branch 1 not taken.
50443078 if(b == 0)
8535 return false;
8536
1/2
✓ Branch 0 taken 50443078 times.
✗ Branch 1 not taken.
50443078 if (b-1 >= joy[joystick_index].num_buttons)
8537 50443078 return false;
8538
8539 return joy[joystick_index].button[b-1].b !=0;
8540 50443078 }
8541
8542 bool joystick(int32_t s)
8543 {
8544 if(s < 0)
8545 return false;
8546 if (s >= joy[joystick_index].num_sticks)
8547 return false;
8548
8549 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8550 {
8551 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8552 return true;
8553 }
8554 return false;
8555 }
8556
8557 const char* joybtn_name(int32_t b)
8558 {
8559 if (b <= 0 || b > joy[joystick_index].num_buttons)
8560 return "";
8561
8562 return joy[joystick_index].button[b-1].name;
8563 }
8564
8565 const char* joystick_name(int32_t s)
8566 {
8567 if (s < 0 || s >= joy[joystick_index].num_sticks)
8568 return "";
8569
8570 return joy[joystick_index].stick[s].name;
8571 }
8572
8573 int32_t button_pressed()
8574 {
8575 if (joystick_index >= MAX_JOYSTICKS)
8576 return 0;
8577
8578 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8579 {
8580 if(joybtn(i))
8581 return i;
8582 }
8583
8584 return 0;
8585 }
8586
8587 int32_t next_press_key();
8588
8589 int32_t next_joy_input(bool buttons)
8590 {
8591 clear_keybuf();
8592
8593 //first, we need to wait until they're pressing no buttons
8594 for(;;)
8595 {
8596 if(keypressed())
8597 {
8598 switch(readkey()>>8)
8599 {
8600 case KEY_ESC:
8601 return -1;
8602
8603 case KEY_SPACE:
8604 return 0;
8605 }
8606 }
8607
8608 poll_joystick();
8609 bool done = true;
8610
8611 if (buttons)
8612 {
8613 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8614 {
8615 if(joybtn(i)) done = false;
8616 }
8617 }
8618 else
8619 {
8620 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8621 {
8622 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8623 return -2;
8624 }
8625 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8626 {
8627 if(joystick(i)) done = false;
8628 }
8629 }
8630
8631 if(done) break;
8632 rest(1);
8633 }
8634
8635 //now, we need to wait for them to press any button
8636 for(;;)
8637 {
8638 if(keypressed())
8639 {
8640 switch(readkey()>>8)
8641 {
8642 case KEY_ESC:
8643 return -1;
8644
8645 case KEY_SPACE:
8646 return 0;
8647 }
8648 }
8649
8650 poll_joystick();
8651
8652 if (buttons)
8653 {
8654 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8655 {
8656 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8657 return -2;
8658 }
8659 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8660 {
8661 if(joybtn(i))
8662 return i;
8663 }
8664 }
8665 else
8666 {
8667 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8668 {
8669 if(joystick(i))
8670 return i;
8671 }
8672 }
8673 rest(1);
8674 }
8675 }
8676
8677 7872867 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8678 {
8679
2/2
✓ Branch 0 taken 7843980 times.
✓ Branch 1 taken 28887 times.
7872867 bool ret = btn && !flag;
8680 7872867 flag = rawbtn;
8681
8682 7872867 return ret;
8683 }
8684 377033792 static bool rButton(bool &btn, bool &flag)
8685 {
8686
2/2
✓ Branch 0 taken 363114777 times.
✓ Branch 1 taken 13919015 times.
377033792 bool ret = btn && !flag;
8687 377033792 flag = btn;
8688
8689 377033792 return ret;
8690 }
8691 4646464 static bool rButtonPeek(bool btn, bool flag)
8692 {
8693
2/2
✓ Branch 0 taken 4299196 times.
✓ Branch 1 taken 347268 times.
4646464 if(!btn)
8694 {
8695 4299196 return false;
8696 }
8697
2/2
✓ Branch 0 taken 33616 times.
✓ Branch 1 taken 313652 times.
347268 else if(!flag)
8698 {
8699 33616 return true;
8700 }
8701
8702 313652 return false;
8703 4646464 }
8704
8705 // Updated only by keyboard/gamepad.
8706 // If in replay mode, this is set directly by the replay system.
8707 // This should never be read from directly - use control_state instead.
8708 bool raw_control_state[ZC_CONTROL_STATES];
8709
8710 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8711 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8712 // lasts until the next call to load_control_state.
8713 bool control_state[ZC_CONTROL_STATES];
8714 bool disable_control[ZC_CONTROL_STATES];
8715 bool drunk_toggle_state[11];
8716 bool disabledKeys[127];
8717 bool KeyInput[127];
8718 bool KeyPress[127];
8719
8720 bool key_current_frame[127];
8721 bool key_previous_frame[127];
8722
8723 static bool key_system[127];
8724 static bool key_system_previous[127];
8725 static bool key_system_press[127];
8726
8727 bool button_press[ZC_CONTROL_STATES];
8728 bool button_hold[ZC_CONTROL_STATES];
8729
8730 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8731 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8732 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8733 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8734 #define STICK_PRECISION 56 //define your own sensitivity
8735
8736 15670253 void load_control_state()
8737 {
8738 15670253 load_control_called_this_frame = true;
8739
8740
2/2
✓ Branch 0 taken 12467191 times.
✓ Branch 1 taken 3203062 times.
15670253 if (replay_version_check(8, 11))
8741 {
8742
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8743 57655116 down_control_states[i] = raw_control_state[i];
8744 3203062 }
8745
8746
2/2
✓ Branch 0 taken 15670232 times.
✓ Branch 1 taken 21 times.
15670253 if (!replay_is_replaying())
8747 {
8748
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8749
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8750
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8751
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8762
8763
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8764 {
8765 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8766 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8767 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8768 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8769 }
8770 else
8771 {
8772 21 raw_control_state[14] = false;
8773 21 raw_control_state[15] = false;
8774 21 raw_control_state[16] = false;
8775 21 raw_control_state[17] = false;
8776 }
8777 21 }
8778
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15670248 times.
15670253 if (replay_is_active())
8779 {
8780
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14458548 times.
15670248 if (replay_get_version() < 3)
8781 1211700 replay_poll();
8782
4/4
✓ Branch 0 taken 14458527 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12697152 times.
✓ Branch 3 taken 1761375 times.
14458548 else if (replay_is_replaying() && replay_get_version() < 6)
8783 1761375 replay_peek_input();
8784
4/4
✓ Branch 0 taken 12697152 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9494090 times.
✓ Branch 3 taken 3203062 times.
12697173 else if (replay_is_replaying() && replay_version_check(8, 11))
8785 3203062 replay_peek_input();
8786
2/2
✓ Branch 0 taken 14330306 times.
✓ Branch 1 taken 1339942 times.
15670248 if (replay_get_version() == 8)
8787 1339942 update_keys();
8788 15670248 }
8789
8790 // Some test replay files were made before a serious input bug was fixed, so instead
8791 // of re-doing them or tossing them out, just check for that zplay version.
8792
3/4
✓ Branch 0 taken 15670243 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15548343 times.
15670253 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8793
2/2
✓ Branch 0 taken 282064374 times.
✓ Branch 1 taken 15670243 times.
297734617 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8794 {
8795 282064374 control_state[i] = raw_control_state[i];
8796
4/4
✓ Branch 0 taken 53024004 times.
✓ Branch 1 taken 229040370 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412010 times.
282064374 if (botched_input && !control_state[i])
8797 50412010 down_control_states[i] = false;
8798 282064374 }
8799 15670243 bool did_bad_cutscene_btn = false;
8800
2/2
✓ Branch 0 taken 15670243 times.
✓ Branch 1 taken 282064374 times.
297734617 for(int q = 0; q < 18; ++q)
8801
4/4
✓ Branch 0 taken 13343636 times.
✓ Branch 1 taken 268720738 times.
✓ Branch 2 taken 13341925 times.
✓ Branch 3 taken 1711 times.
282066085 if(control_state[q] && !active_cutscene.can_button(q))
8802 {
8803 1711 control_state[q] = false;
8804 1711 did_bad_cutscene_btn = true;
8805 1711 }
8806
2/2
✓ Branch 0 taken 15668976 times.
✓ Branch 1 taken 1267 times.
15670243 if(did_bad_cutscene_btn)
8807 1267 active_cutscene.error();
8808
8809 15670243 button_press[0]=rButton(control_state[0],button_hold[0]);
8810 15670243 button_press[1]=rButton(control_state[1],button_hold[1]);
8811 15670243 button_press[2]=rButton(control_state[2],button_hold[2]);
8812 15670243 button_press[3]=rButton(control_state[3],button_hold[3]);
8813 15670243 button_press[4]=rButton(control_state[4],button_hold[4]);
8814 15670243 button_press[5]=rButton(control_state[5],button_hold[5]);
8815 15670243 button_press[6]=rButton(control_state[6],button_hold[6]);
8816 15670243 button_press[7]=rButton(control_state[7],button_hold[7]);
8817 15670243 button_press[8]=rButton(control_state[8],button_hold[8]);
8818 15670243 button_press[9]=rButton(control_state[9],button_hold[9]);
8819 15670243 button_press[10]=rButton(control_state[10],button_hold[10]);
8820 15670243 button_press[11]=rButton(control_state[11],button_hold[11]);
8821 15670243 button_press[12]=rButton(control_state[12],button_hold[12]);
8822 15670243 button_press[13]=rButton(control_state[13],button_hold[13]);
8823 15670243 button_press[14]=rButton(control_state[14],button_hold[14]);
8824 15670243 button_press[15]=rButton(control_state[15],button_hold[15]);
8825 15670243 button_press[16]=rButton(control_state[16],button_hold[16]);
8826 15670243 button_press[17]=rButton(control_state[17],button_hold[17]);
8827 15670243 }
8828
8829 // Returns true if any game key is pressed. This is needed because keypressed()
8830 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8831 78829768 bool zc_key_pressed()
8832 //may also need to use zc_getrawkey
8833 {
8834
7/10
✓ Branch 0 taken 63670106 times.
✓ Branch 1 taken 15159662 times.
✓ Branch 2 taken 15159662 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15159662 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12423691 times.
✓ Branch 7 taken 12423691 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4963549 times.
83793317 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8835
4/6
✓ Branch 0 taken 12423691 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12423691 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9459713 times.
✓ Branch 5 taken 9459713 times.
12423691 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8836
4/6
✓ Branch 0 taken 9459713 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9459713 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6261244 times.
✓ Branch 5 taken 6261244 times.
9459713 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8837
4/6
✓ Branch 0 taken 6261244 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6261244 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5373391 times.
✓ Branch 5 taken 5373391 times.
6261244 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8838
1/2
✓ Branch 0 taken 5373391 times.
✗ Branch 1 not taken.
5373391 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8839
3/4
✓ Branch 0 taken 5185551 times.
✓ Branch 1 taken 187840 times.
✓ Branch 2 taken 5185551 times.
✗ Branch 3 not taken.
5373391 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8840
3/4
✓ Branch 0 taken 5038582 times.
✓ Branch 1 taken 146969 times.
✓ Branch 2 taken 5038582 times.
✗ Branch 3 not taken.
5185551 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8841
3/4
✓ Branch 0 taken 5016365 times.
✓ Branch 1 taken 22217 times.
✓ Branch 2 taken 5016365 times.
✗ Branch 3 not taken.
5038582 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8842
3/4
✓ Branch 0 taken 4989996 times.
✓ Branch 1 taken 26369 times.
✓ Branch 2 taken 4989996 times.
✗ Branch 3 not taken.
5016365 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8843
3/4
✓ Branch 0 taken 4982711 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4982711 times.
✗ Branch 3 not taken.
4989996 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8844
3/4
✓ Branch 0 taken 4965472 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 4965472 times.
✗ Branch 3 not taken.
4982711 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8845
3/4
✓ Branch 0 taken 4963643 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 4963643 times.
✗ Branch 3 not taken.
4965472 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8846
3/4
✓ Branch 0 taken 4963608 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4963608 times.
✗ Branch 3 not taken.
4963643 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8847
2/2
✓ Branch 0 taken 4963549 times.
✓ Branch 1 taken 59 times.
4963608 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8848 140902297 return true;
8849
8850 4963549 return false;
8851 18525634 }
8852
8853 300058166 bool getInput(int32_t btn, int input_flags)
8854 {
8855
3/4
✓ Branch 0 taken 267154144 times.
✓ Branch 1 taken 32904022 times.
✓ Branch 2 taken 267154144 times.
✗ Branch 3 not taken.
300058166 if((input_flags & INPUT_HERO_ACTION) && Hero.no_control())
8856 return false;
8857
8858 300058166 bool press = input_flags & INPUT_PRESS;
8859 300058166 bool drunk = input_flags & INPUT_DRUNK;
8860 300058166 bool ignoreDisable = input_flags & INPUT_IGNORE_DISABLE;
8861 300058166 bool eatEntirely = input_flags & INPUT_EAT_ENTIRELY;
8862 300058166 bool peek = input_flags & INPUT_PEEK;
8863
8864 300058166 bool ret = false, drunkstate = false, rawret = false;;
8865 300058166 bool* flag = &down_control_states[btn];
8866
2/7
✓ Branch 0 taken 281513623 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18544543 times.
300058166 switch(btn)
8867 {
8868 case btnF12:
8869 ret = zc_getkey(KEY_F12, ignoreDisable);
8870 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8871 eatEntirely = false;
8872 break;
8873 case btnF11:
8874 ret = zc_getkey(KEY_F11, ignoreDisable);
8875 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8876 eatEntirely = false;
8877 break;
8878 case btnF5:
8879 ret = zc_getkey(KEY_F5, ignoreDisable);
8880 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8881 eatEntirely = false;
8882 break;
8883 case btnQ:
8884 ret = zc_getkey(KEY_Q, ignoreDisable);
8885 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8886 eatEntirely = false;
8887 break;
8888 case btnI:
8889 ret = zc_getkey(KEY_I, ignoreDisable);
8890 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8891 eatEntirely = false;
8892 break;
8893 case btnM:
8894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18544543 times.
18544543 if(FFCore.kb_typing_mode) return false;
8895 18544543 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8896 18544543 eatEntirely = false;
8897 18544543 break;
8898 default: //control_state[] index
8899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 281513623 times.
281513623 if(FFCore.kb_typing_mode) return false;
8900
6/6
✓ Branch 0 taken 280133337 times.
✓ Branch 1 taken 1380286 times.
✓ Branch 2 taken 18175410 times.
✓ Branch 3 taken 261957927 times.
✓ Branch 4 taken 18172437 times.
✓ Branch 5 taken 2973 times.
281513623 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8901
2/2
✓ Branch 0 taken 15938150 times.
✓ Branch 1 taken 265572500 times.
281510650 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8902
4/4
✓ Branch 0 taken 250206886 times.
✓ Branch 1 taken 31306737 times.
✓ Branch 2 taken 7168 times.
✓ Branch 3 taken 31299569 times.
312820360 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8903 281513623 rawret = raw_control_state[btn];
8904 281513623 }
8905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 300058166 times.
300058166 assert(flag);
8906
2/2
✓ Branch 0 taken 192569417 times.
✓ Branch 1 taken 107488749 times.
300058166 if(press)
8907 {
8908
2/2
✓ Branch 0 taken 4646464 times.
✓ Branch 1 taken 102842285 times.
107488749 if(peek)
8909 4646464 ret = rButtonPeek(ret, *flag);
8910
2/2
✓ Branch 0 taken 94969418 times.
✓ Branch 1 taken 7872867 times.
102842285 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8911 7872867 else ret = rButton(ret, *flag, rawret);
8912 107488749 }
8913
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 300058166 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
300058166 if(eatEntirely && ret) control_state[btn] = false;
8914
4/4
✓ Branch 0 taken 224550634 times.
✓ Branch 1 taken 75507532 times.
✓ Branch 2 taken 224550553 times.
✓ Branch 3 taken 81 times.
300058166 if(drunk && drunkstate) ret = !ret;
8915 300058166 return ret;
8916 300058166 }
8917
8918 15052521 byte getIntBtnInput(byte intbtn, int input_flags)
8919 {
8920 15052521 byte ret = 0;
8921
2/2
✓ Branch 0 taken 10628315 times.
✓ Branch 1 taken 4424206 times.
15052521 if(intbtn & INT_BTN_A) ret |= getInput(btnA, input_flags) ? INT_BTN_A : 0;
8922
2/2
✓ Branch 0 taken 14843555 times.
✓ Branch 1 taken 208966 times.
15052521 if(intbtn & INT_BTN_B) ret |= getInput(btnB, input_flags) ? INT_BTN_B : 0;
8923
2/2
✓ Branch 0 taken 14844873 times.
✓ Branch 1 taken 207648 times.
15052521 if(intbtn & INT_BTN_L) ret |= getInput(btnL, input_flags) ? INT_BTN_L : 0;
8924
2/2
✓ Branch 0 taken 14844873 times.
✓ Branch 1 taken 207648 times.
15052521 if(intbtn & INT_BTN_R) ret |= getInput(btnR, input_flags) ? INT_BTN_R : 0;
8925
2/2
✓ Branch 0 taken 14844873 times.
✓ Branch 1 taken 207648 times.
15052521 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, input_flags) ? INT_BTN_EX1 : 0;
8926
2/2
✓ Branch 0 taken 14844873 times.
✓ Branch 1 taken 207648 times.
15052521 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, input_flags) ? INT_BTN_EX2 : 0;
8927
2/2
✓ Branch 0 taken 14844873 times.
✓ Branch 1 taken 207648 times.
15052521 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, input_flags) ? INT_BTN_EX3 : 0;
8928
2/2
✓ Branch 0 taken 14844758 times.
✓ Branch 1 taken 207763 times.
15052521 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, input_flags) ? INT_BTN_EX4 : 0;
8929 15052521 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8930 }
8931
8932 7513 byte checkIntBtnVal(byte intbtn, byte vals)
8933 {
8934 7513 return intbtn&vals;
8935 }
8936
8937 208698 bool Up()
8938 {
8939 208698 return getInput(btnUp);
8940 }
8941 208697 bool Down()
8942 {
8943 208697 return getInput(btnDown);
8944 }
8945 208697 bool Left()
8946 {
8947 208697 return getInput(btnLeft);
8948 }
8949 208697 bool Right()
8950 {
8951 208697 return getInput(btnRight);
8952 }
8953 530261 bool cAbtn()
8954 {
8955 530261 return getInput(btnA);
8956 }
8957 3306494 bool cBbtn()
8958 {
8959 3306494 return getInput(btnB);
8960 }
8961 bool cSbtn()
8962 {
8963 return getInput(btnS);
8964 }
8965 208608 bool cLbtn()
8966 {
8967 208608 return getInput(btnL);
8968 }
8969 208608 bool cRbtn()
8970 {
8971 208608 return getInput(btnR);
8972 }
8973 bool cPbtn()
8974 {
8975 return getInput(btnP);
8976 }
8977 bool cEx1btn()
8978 {
8979 return getInput(btnEx1);
8980 }
8981 bool cEx2btn()
8982 {
8983 return getInput(btnEx2);
8984 }
8985 bool cEx3btn()
8986 {
8987 return getInput(btnEx3);
8988 }
8989 bool cEx4btn()
8990 {
8991 return getInput(btnEx4);
8992 }
8993 bool AxisUp()
8994 {
8995 return getInput(btnAxisUp);
8996 }
8997 bool AxisDown()
8998 {
8999 return getInput(btnAxisDown);
9000 }
9001 bool AxisLeft()
9002 {
9003 return getInput(btnAxisLeft);
9004 }
9005 bool AxisRight()
9006 {
9007 return getInput(btnAxisRight);
9008 }
9009
9010 bool cMbtn()
9011 {
9012 return getInput(btnM);
9013 }
9014 bool cF12()
9015 {
9016 return getInput(btnF12);
9017 }
9018 bool cF11()
9019 {
9020 return getInput(btnF11);
9021 }
9022 bool cF5()
9023 {
9024 return getInput(btnF5);
9025 }
9026 bool cQ()
9027 {
9028 return getInput(btnQ);
9029 }
9030 bool cI()
9031 {
9032 return getInput(btnI);
9033 }
9034
9035 211312 bool rUp()
9036 {
9037 211312 return getInput(btnUp, INPUT_PRESS);
9038 }
9039 211099 bool rDown()
9040 {
9041 211099 return getInput(btnDown, INPUT_PRESS);
9042 }
9043 210903 bool rLeft()
9044 {
9045 210903 return getInput(btnLeft, INPUT_PRESS);
9046 }
9047 210163 bool rRight()
9048 {
9049 210163 return getInput(btnRight, INPUT_PRESS);
9050 }
9051 4648 bool rAbtn()
9052 {
9053 4648 return getInput(btnA, INPUT_PRESS);
9054 }
9055 bool rBbtn()
9056 {
9057 return getInput(btnB, INPUT_PRESS);
9058 }
9059 210364 bool rSbtn()
9060 {
9061 210364 return getInput(btnS, INPUT_PRESS);
9062 }
9063 18525634 bool rMbtn()
9064 {
9065 18525634 return getInput(btnM, INPUT_PRESS);
9066 }
9067 186046 bool rLbtn()
9068 {
9069 186046 return getInput(btnL, INPUT_PRESS);
9070 }
9071 186041 bool rRbtn()
9072 {
9073 186041 return getInput(btnR, INPUT_PRESS);
9074 }
9075 208608 bool rPbtn()
9076 {
9077 208608 return getInput(btnP, INPUT_PRESS);
9078 }
9079 bool rEx1btn()
9080 {
9081 return getInput(btnEx1, INPUT_PRESS);
9082 }
9083 bool rEx2btn()
9084 {
9085 return getInput(btnEx2, INPUT_PRESS);
9086 }
9087 186037 bool rEx3btn()
9088 {
9089 186037 return getInput(btnEx3, INPUT_PRESS);
9090 }
9091 186037 bool rEx4btn()
9092 {
9093 186037 return getInput(btnEx4, INPUT_PRESS);
9094 }
9095 bool rAxisUp()
9096 {
9097 return getInput(btnAxisUp, INPUT_PRESS);
9098 }
9099 bool rAxisDown()
9100 {
9101 return getInput(btnAxisDown, INPUT_PRESS);
9102 }
9103 bool rAxisLeft()
9104 {
9105 return getInput(btnAxisLeft, INPUT_PRESS);
9106 }
9107 bool rAxisRight()
9108 {
9109 return getInput(btnAxisRight, INPUT_PRESS);
9110 }
9111
9112 bool rF11()
9113 {
9114 return getInput(btnF11, INPUT_PRESS);
9115 }
9116 bool rQ()
9117 {
9118 return getInput(btnQ, INPUT_PRESS);
9119 }
9120 bool rI()
9121 {
9122 return getInput(btnI, INPUT_PRESS);
9123 }
9124
9125 bool DrunkUp()
9126 {
9127 return getInput(btnUp, INPUT_DRUNK);
9128 }
9129 bool DrunkDown()
9130 {
9131 return getInput(btnDown, INPUT_DRUNK);
9132 }
9133 bool DrunkLeft()
9134 {
9135 return getInput(btnLeft, INPUT_DRUNK);
9136 }
9137 bool DrunkRight()
9138 {
9139 return getInput(btnRight, INPUT_DRUNK);
9140 }
9141 bool DrunkcAbtn()
9142 {
9143 return getInput(btnA, INPUT_DRUNK);
9144 }
9145 bool DrunkcBbtn()
9146 {
9147 return getInput(btnB, INPUT_DRUNK);
9148 }
9149 bool DrunkcEx1btn()
9150 {
9151 return getInput(btnEx1, INPUT_DRUNK);
9152 }
9153 bool DrunkcEx2btn()
9154 {
9155 return getInput(btnEx2, INPUT_DRUNK);
9156 }
9157 bool DrunkcSbtn()
9158 {
9159 return getInput(btnS, INPUT_DRUNK);
9160 }
9161 bool DrunkcMbtn()
9162 {
9163 return getInput(btnM, INPUT_DRUNK);
9164 }
9165 bool DrunkcLbtn()
9166 {
9167 return getInput(btnL, INPUT_DRUNK);
9168 }
9169 bool DrunkcRbtn()
9170 {
9171 return getInput(btnR, INPUT_DRUNK);
9172 }
9173 bool DrunkcPbtn()
9174 {
9175 return getInput(btnP, INPUT_DRUNK);
9176 }
9177
9178 bool DrunkrUp()
9179 {
9180 return getInput(btnUp, INPUT_PRESS | INPUT_DRUNK);
9181 }
9182 bool DrunkrDown()
9183 {
9184 return getInput(btnDown, INPUT_PRESS | INPUT_DRUNK);
9185 }
9186 bool DrunkrLeft()
9187 {
9188 return getInput(btnLeft, INPUT_PRESS | INPUT_DRUNK);
9189 }
9190 bool DrunkrRight()
9191 {
9192 return getInput(btnRight, INPUT_PRESS | INPUT_DRUNK);
9193 }
9194 bool DrunkrAbtn()
9195 {
9196 return getInput(btnA, INPUT_PRESS | INPUT_DRUNK);
9197 }
9198 bool DrunkrBbtn()
9199 {
9200 return getInput(btnB, INPUT_PRESS | INPUT_DRUNK);
9201 }
9202 bool DrunkrEx1btn()
9203 {
9204 return getInput(btnEx1, INPUT_PRESS | INPUT_DRUNK);
9205 }
9206 bool DrunkrEx2btn()
9207 {
9208 return getInput(btnEx2, INPUT_PRESS | INPUT_DRUNK);
9209 }
9210 bool DrunkrEx3btn()
9211 {
9212 return getInput(btnEx3, INPUT_PRESS | INPUT_DRUNK);
9213 }
9214 bool DrunkrEx4btn()
9215 {
9216 return getInput(btnEx4, INPUT_PRESS | INPUT_DRUNK);
9217 }
9218 bool DrunkrSbtn()
9219 {
9220 return getInput(btnS, INPUT_PRESS | INPUT_DRUNK);
9221 }
9222 bool DrunkrMbtn()
9223 {
9224 return getInput(btnM, INPUT_PRESS | INPUT_DRUNK);
9225 }
9226 bool DrunkrLbtn()
9227 {
9228 return getInput(btnL, INPUT_PRESS | INPUT_DRUNK);
9229 }
9230 bool DrunkrRbtn()
9231 {
9232 return getInput(btnR, INPUT_PRESS | INPUT_DRUNK);
9233 }
9234 bool DrunkrPbtn()
9235 {
9236 return getInput(btnP, INPUT_PRESS | INPUT_DRUNK);
9237 }
9238
9239 18909 void eat_buttons()
9240 {
9241 18909 getInput(btnA, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9242 18909 getInput(btnB, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9243 18909 getInput(btnS, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9244 18909 getInput(btnM, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9245 18909 getInput(btnL, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9246 18909 getInput(btnR, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9247 18909 getInput(btnP, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9248 18909 getInput(btnEx1, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9249 18909 getInput(btnEx2, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9250 18909 getInput(btnEx3, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9251 18909 getInput(btnEx4, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9252 18909 }
9253
9254 // Is true for the _first frame_ of a key press.
9255 // But! it is possible that a script manually sets the value of KeyPress,
9256 // in which case it will be restored to the "true" value based on `key_current_frame`
9257 // and `key_previous_frame` on the next frame.
9258 47 bool zc_readkey(int32_t k, bool ignoreDisable)
9259 {
9260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if(ignoreDisable) return KeyPress[k];
9261
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 switch(k)
9262 {
9263 case KEY_F7:
9264 case KEY_F8:
9265 case KEY_F9:
9266 return KeyPress[k];
9267
9268 default:
9269
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 1 times.
47 return KeyPress[k] && !disabledKeys[k];
9270 }
9271 47 }
9272
9273 // Is true for _every frame_ a key is held down.
9274 // But! it is possible that a script manually sets the value of KeyInput,
9275 // in which case it will be restored to the "true" value based on `key_current_frame`
9276 // on the next frame.
9277 bool zc_getkey(int32_t k, bool ignoreDisable)
9278 {
9279 if(ignoreDisable) return KeyInput[k];
9280 switch(k)
9281 {
9282 case KEY_F7:
9283 case KEY_F8:
9284 case KEY_F9:
9285 return KeyInput[k];
9286
9287 default:
9288 return KeyInput[k] && !disabledKeys[k];
9289 }
9290 }
9291
9292 // Reads (and then clears) the current frame key state directly.
9293 // Scripts can also modify `key_current_frame`.
9294 903 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9295 {
9296
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 901 times.
903 if(zc_getrawkey(k, ignoreDisable))
9297 {
9298 2 _key[k]=key[k]=key_current_frame[k]=0;
9299 2 return true;
9300 }
9301 901 _key[k]=key[k]=key_current_frame[k]=0;
9302 901 return false;
9303 903 }
9304
9305 // Reads the current frame key state directly.
9306 // Scripts can also modify `key_current_frame`.
9307 125855003 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9308 {
9309
2/2
✓ Branch 0 taken 107329275 times.
✓ Branch 1 taken 18525728 times.
125855003 if(ignoreDisable) return key_current_frame[k];
9310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18525728 times.
18525728 switch(k)
9311 {
9312 case KEY_F7:
9313 case KEY_F8:
9314 case KEY_F9:
9315 return key_current_frame[k];
9316
9317 default:
9318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18525728 times.
18525728 return key_current_frame[k] && !disabledKeys[k];
9319 }
9320 125855003 }
9321
9322 // Only used for a handful of keys, like tilde and Function keys.
9323 // This state is never read within the game.
9324 // It exists so that all keyboard input still functions during replay,
9325 // without inadvertently doing things like toggling throttling if the player
9326 // presses ~
9327 bool zc_get_system_key(int32_t k)
9328 {
9329 return key_system[k];
9330 }
9331
9332 // True for the _first_ frame of a key press.
9333 166730706 bool zc_read_system_key(int32_t k)
9334 {
9335 166730706 return key_system_press[k];
9336 }
9337
9338 2352755518 bool is_system_key(int32_t k)
9339 {
9340
2/2
✓ Branch 0 taken 2186024812 times.
✓ Branch 1 taken 166730706 times.
2352755518 switch (k)
9341 {
9342 case KEY_BACKQUOTE:
9343 case KEY_CLOSEBRACE:
9344 case KEY_END:
9345 case KEY_HOME:
9346 case KEY_OPENBRACE:
9347 case KEY_PGDN:
9348 case KEY_PGUP:
9349 case KEY_TAB:
9350 case KEY_TILDE:
9351 166730706 return true;
9352 }
9353 2186024812 return is_Fkey(k);
9354 2352755518 }
9355
9356 18525634 void update_system_keys()
9357 {
9358
2/2
✓ Branch 0 taken 2352755518 times.
✓ Branch 1 taken 18525634 times.
2371281152 for (int32_t q = 0; q < 127; ++q)
9359 {
9360
2/2
✓ Branch 0 taken 389038314 times.
✓ Branch 1 taken 1963717204 times.
2352755518 if (!is_system_key(q))
9361 1963717204 continue;
9362
9363 389038314 key_system[q] = key[q];
9364
1/2
✓ Branch 0 taken 389038314 times.
✗ Branch 1 not taken.
389038314 key_system_press[q] = key_system[q] && !key_system_previous[q];
9365 389038314 key_system_previous[q] = key_system[q];
9366 389038314 }
9367 18525634 }
9368
9369 19865576 void update_keys()
9370 {
9371
2/2
✓ Branch 0 taken 2522928152 times.
✓ Branch 1 taken 19865576 times.
2542793728 for (int32_t q = 0; q < 127; ++q)
9372 {
9373 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9374
2/2
✓ Branch 0 taken 2522915452 times.
✓ Branch 1 taken 12700 times.
2522928152 if (!replay_is_replaying())
9375 12700 key_current_frame[q] = key[q];
9376
9377
2/2
✓ Branch 0 taken 2503540523 times.
✓ Branch 1 taken 19387629 times.
2522928152 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9378 2522928152 KeyInput[q] = key_current_frame[q];
9379 2522928152 key_previous_frame[q] = key_current_frame[q];
9380 2522928152 }
9381 19865576 }
9382
9383